如何将滚动条固定在某个位置 slimscroll插件

html-css018

如何将滚动条固定在某个位置 slimscroll插件,第1张

//html

<body>

<div style="background:#003366height:500px">空div</div>

<div class="purple" style="height:500pxwidth:200pxbackground:purple">

<div class="nb" style="height:100pxwidth:100pxbackground:#9966FF">移动到顶部固定不变</div>

</div>

<div class="red" style="background:#ff0000height:1500px">空div</div>

<div style="background:#cccheight:1500px">空div</div>

<div class="nb2" style="height:100pxwidth:100pxbackground:gray">移动到底部固定不变</div>

</body>

//js

$(function(){

//获取要定位元素距离浏览器顶部的距离

var navH = $(".nb").offset().top

var navH2 = $(".nb2").offset().top

var Pur= $(".purple").offset().top//紫色块

var Red= $(".red").offset().top//红色块

//滚动条事件

$(window).scroll(function(){

//获取滚动条的滑动距离

var scroH = $(this).scrollTop()

//滚动条的滑动距离大于等于定位元素距离浏览器顶部的距离,就固定,反之就不固定

if(scroH>=navH){

$(".nb").css({"position":"fixed","top":0})

}else if(scroH<navH){

$(".nb").css({"position":"static"})

}

if(scroH <= navH2){

$(".nb2").css({"position":"fixed","bottom":"15px","right":"15px"})

}else if(scroH<navH){

$(".nb2").css({"position":"static"})

}

if(scroH >= Pur &&scroH <= Red){

$(".nb").css({"position":"static"}) //在紫色块的时候不固定

$(".nb2").css({"position":"static"}) //在紫色块的时候不固定

}

})

})

不需要。

CSS3注册表单滑动切换特效是一款滑动显示表单和注册表单效果代码,是系统自带的效果代码,不需要再单独安装插件就可以显示。

层叠样式表(英文全称:CascadingStyleSheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言,CSS不仅可以静态地修饰网页,还可以配合各种脚本语言动态地对网页各元素进行格式化。