该插件具有响应式的特点,你可以设定一个最小的视口宽度值,当屏幕小于这个宽度时,元素就不会再位置固定(例如可以在手机和平板上将元素占据满整列)。
使用jquery.pinBox插件需要在页面中引入jquery1.7+和jquery.pinBox.min.js文件。
<!-- jQuery -->
<
script
src
=
"jquery-1.9.1.min.js"
></
>
<!-- Include pinBox plugin -->
"js/jquery.pinBox.min.js"
你不需要进行任何特殊的设置,只需要将你需要滚动固定的元素放置在一个容器中,例如下面的代码中的#pinBoxContainer,通过为固定元素添加一个class,例如.pinBox。
#pinBoxContainer
.pinBox
<!-- container with id -->
div
class
"container"
id
"pinBoxContainer"
<!--如果你不使用bootstrap.css,并且div的父元素是浮动(float)的,就要确保为其添加一个[position:relative]属性-->
"col-sm-4"
<!-- box you want to pin inside [id="pinBoxContainer"] have class or id -->
"pinBox"
h2
"headColor"
>Example box</
p
>some text</
</
"col-sm-8"
在页面初始化完毕之后,可以通过下面的方法来初始化该插件。
$(document).ready(
function
() {
$(
".pinBox"
).pinBox({
Top :
'50px'
,
Container :
'#pinBoxContainer'
});
//default 0px
//default '.container'
//default 20
ZIndex : 20,
//default '767px' if you disable pinBox in mobile or tablet
MinWidth :
'767px'
//events if scrolled or window resized
Events :
(e){
console.log(e);
// e.current => current scroll top [number]
// e.direction => scroll down or up [up,down]
// e.width => window width [number]
// e.active => if pinBox active [true,false]
// e.disabled => if window width > MinWidth pinBox will disabled [true, false]
}
Top
Container
.container
ZIndex
MinWidth
Events
jquery.pinBox官方网站地址为:http://nezamy.com/pinBox/
2018-09-03
2018-08-22
2018-08-15
2018-08-11
2018-08-07
2018-12-13
2018-11-15
2015-07-21
2015-07-22
2015-07-24