博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
headroom.js插件使用方法
阅读量:4308 次
发布时间:2019-06-06

本文共 6082 字,大约阅读时间需要 20 分钟。

1.什么是headroom.js?

headroom是用纯Javascript写的插件,用来隐藏和展示页面元素,从而为页面留下更多空间。比如使用headroom能使导航栏当页面下滚时消失,当页面上滚时候又出现。(

2.工作原理

通过感应目标元素不同的3种状态(原始,下滚,上滚),为目标元素更改相应的class,通过相应的class的css样式的变化得到所要的效果。

3.如何使用

(以下的例子是基于bootstrap框架和jquery插件的,在bootstrap框架下可以快速写出导航栏navbar,然后以jquery插件方式对导航栏navbar调用headroom()。)

首先需要引用headroom.js和jQuery.headroom.js。将以下的代码加入到你的代码中。headroom.js作用:感应元素不同的状态为之更改相应的class。jQuery.headroom.js作用:提供jquery插件方式和Data-API方式调用headrooom()。

因为headroom()函数传入的参数option对象的默认值如下。

 

{    // 在元素没有固定之前,垂直方向的偏移量(以px为单位)    offset : 0,    // scroll tolerance in px before state changes    tolerance : 0,    // 对于每个状态都可以自定义css classes     classes : {        // 当元素初始化后所设置的class        initial : "headroom",        // 向上滚动时设置的class        pinned : "headroom--pinned",        // 向下滚动时所设置的class        unpinned : "headroom--unpinned"    }}

 

由此可知原始的状态对应的class是headroom,下滚时的class是headroom--pinned,上滚时的class是headroom--unpinned。所以我们要添加下面的样式,通过css的trasition属性达到变换效果。

 

 

之后添加下面的js代码,使用jquery插件的方式调用。".navbar-fixed-top"只是用来获取导航栏navbar,也可以用其他选择器来获取navbar目标元素

 

 

做完了上述步骤,理论上你就可以看到headroom的效果了,如果没有成功可能是以下的原因:

1、js的引用顺序错误,因为一些js要用到其他js才能运行的,所以必须放在其他的js之后。例如

必须放在headroom.js和jQuery.headroom.js之后,而headroom.js和jQuery.headroom.js必须放在jQuery.js之后。

2、将$(".navbar-fixed-top").headroom(); 放在主体html代码之前,如放在<head></head>中,因为在主体html代码之前,navbar元素还没加载就调用 了headroom(),所以无效。应该用以下代码替换之,表示等文档加载完毕再调用。

上述的效果只是通过css自带的trasition属性来实现效果,比较单调。不过可以结合animate.css实现更多的漂亮的消失和出现的效果。()

animate.css使用纯css为各种元素实现不同的动画效果,每一种class对应一种动画效果,所以将animate.css引入代码后headroom()可以直接使用已经写好的class。()

我基于bootstrap和jquery写得例子。

 

1   2   3     4     Bootstrap 101 Template  5     
6
7
8 9
10 11
12
13
17 22 23 30 31 32 33 34 35
36
37
38

Hello, world!

39

This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.

40

Learn more »

41
42
43 44
45 46
47
68 69
70
71

PHP

72

PHP, an acronym for Hypertext Preprocessor, is a widely-used open source general-purpose scripting language. It is an HTML embedded scripting language and is especially suited for web development. The basic syntax of PHP is similar to C, Java, and Perl, and is easy to learn. PHP is used for creating interactive and dynamic web pages quickly, but you can do much more with PHP. 73

74

JS

75

76 JavaScript is a cross-platform, object-oriented scripting language developed by Netscape. JavaScript was created by Netscape programmer Brendan Eich. It was first released under the name of LiveScript as part of Netscape Navigator 2.0 in September 1995. It was renamed JavaScript on December 4, 1995. As JavaScript works on the client side, It is mostly used for client-side web development. 77

78

MySQL

79

80 MySQL tutorial of w3cschool is a comprhensive tutorial to learn MySQL. We have hundreds of examples covered, often with PHP code. This helps you to learn how to create PHP-MySQL based web applications. 81

82

PostgreSQL

83

84 In 1986 the Defense Advanced Research Projects Agency (DARPA), the Army Research Office (ARO), the National Science Foundation (NSF), and ESL, Inc sponsored Berkeley POSTGRES Project which was led by Michael Stonebrakessr. In 1987 the first demo version of the project is released. In June 1989, Version 1 was released to some external users. Version 2 and 3 were released in 1990 and 1991. Version 3 had support for multiple storage managers, an query executor was improved, rule system was rewritten. After that, POSTGRES has been started to be implemented in various research and development projects. For example, in late 1992, POSTGRES became the primary data manager for the Sequoia 2000 scientific computing project4. User community around the project also has been started increasing; by 1993, it was doubled. 85

86

MongoDB

87

88 The term NoSQL was coined by Carlo Strozzi in the year 1998. He used this term to name his Open Source, Light Weight, DataBase which did not have an SQL interface.In the early 2009, when last.fm wanted to organize an event on open-source distributed databases, Eric Evans, a Rackspace employee, reused the term to refer databases which are non-relational, distributed, and does not conform to atomicity, consistency, isolation, durability - four obvious features of traditional relational database systems. 89

90

91 After reading the largest third party online MySQL tutorial by w3cschool, you will be able to install, manage and develop PHP-MySQL web applications by your own. We have a comprehensive, SQL TUTORIAL, which will help you to understand how to prepare queries to fetch data against various conditions. 92

93 94
95
96 97 98
99 100
101 102 103 104 105 106 107 108 113 114 115 116

 

原文地址:

 

 

 

 

转载于:https://www.cnblogs.com/ccode/p/3905922.html

你可能感兴趣的文章
克罗谈投资策略04_感觉与现实
查看>>
通向财务自由之路01_导读
查看>>
通向财务自由之路02_成功的决定因素:你
查看>>
中低频量化交易策略研发01_引言
查看>>
中低频量化交易策略研发06_推进的择时策略
查看>>
史丹·温斯坦称傲牛熊市的秘密
查看>>
期货市场技术分析01_理论基础
查看>>
期货市场技术分析02_趋势的基本概念
查看>>
期货市场技术分析03_主要反转形态
查看>>
期货市场技术分析04_持续形态
查看>>
期货市场技术分析05_交易量和持仓兴趣
查看>>
TB交易开拓者入门教程
查看>>
TB创建公式应用dll失败 请检查用户权限,终极解决方案
查看>>
python绘制k线图(蜡烛图)报错 No module named 'matplotlib.finance
查看>>
talib均线大全
查看>>
期货市场技术分析06_长期图表和商品指数
查看>>
期货市场技术分析07_摆动指数和相反意见理论
查看>>
满屏的指标?删了吧,手把手教你裸 K 交易!
查看>>
不吹不黑 | 聊聊为什么要用99%精度的数据回测
查看>>
对于模拟交易所引发的思考
查看>>