html+css+jquery实现网站滚动条整屏滑动特效

2025-11-04 07:31:36

1、新建html文档。

html+css+jquery实现网站滚动条整屏滑动特效

2、书写hmtl代码。

<div style="height:2000px;">

 <div id="s1" class="pager"></div>

 <div id="s2" class="pager"></div>

 <div id="s3" class="pager"></div>

 <div id="s4" class="pager"></div>

 <div id="s5" class="pager"></div>

</div>

html+css+jquery实现网站滚动条整屏滑动特效

3、书写css代码。

<style>

body { margin: 0; padding: 0 }

#s1 { height: 800px; background:#0F3}

#s2 { height: 800px; background:#60C}

#s3 { height: 800px; background:#903}

#s4 { height: 800px; background:#CCF}

#s5 { height: 800px; background:#FFC}

</style>

html+css+jquery实现网站滚动条整屏滑动特效

4、添加js代码。

<script src="jquery.min.js"></script>

<script src="jquery.mousewheel.js"></script> 

<script src="nicescroll.js"></script> 

html+css+jquery实现网站滚动条整屏滑动特效

5、书写js代码。

<script>

jQuery(function($) {

var iPagerCount=$(".pager").length;

var iPageNumber=0;

var aTop=[0,800,1600,2400,3200,4000,4600];

var sTop=$(window).scrollTop();

if(sTop>=aTop[0]&&sTop<aTop[1]){iPageNumber=0;}

if(sTop>=aTop[1]&&sTop<aTop[2]){iPageNumber=1;}

if(sTop>=aTop[2]&&sTop<aTop[3]){iPageNumber=2;}

if(sTop>=aTop[3]&&sTop<aTop[4]){iPageNumber=3;}

if(sTop>=aTop[4]&&sTop<aTop[5]){iPageNumber=4;}

if(sTop>=aTop[5]&&sTop<aTop[6]){iPageNumber=5;}

if(sTop>=aTop[6]){iPageNumber=6;}

//美化浏览器的滚动条

$("html").niceScroll({

touchbehavior:false,cursorcolor:"#0966ce",cursoropacitymax:1,cursorwidth:8,horizrailenabled:true,cursorborderradius:5,autohidemode:true,background:'none',cursorborder:'solid 1px #0966ce'

});

//滑动滚动条翻屏效果

$("html,body").bind("mousewheel",function(event,intDelta){

var $this=$(this),

timeoutId=$(this).data('timeoutId');

if(timeoutId){

clearTimeout(timeoutId);

}

$this.data('timeoutId',setTimeout(function(){

intDelta>0?pageUp():pageDown();$this.removeData('timeoutId');$this=null;

},150));

return false;

});

function pageUp(){

iPageNumber=iPageNumber<=0?0:iPageNumber-1;slide(aTop[iPageNumber]);

}

function pageDown(){

iPageNumber=iPageNumber>=iPagerCount-1?iPageNumber:iPageNumber+1;slide(aTop[iPageNumber]);

}

function slide(length){

$("body,html").stop().animate({scrollTop:length},800,'easeOutExpo');

}

//扩展动画

$.extend($.easing,{

easeOutExpo:function(e,f,a,h,g){

return(f==g)?a+h:h*(-Math.pow(2,-10*f/g)+1)+a

},easeOutBounce:function(x,t,b,c,d){

if((t/=d)<(1/2.75)){

return c*(7.5625*t*t)+b;

}else if(t<(2/2.75)){

return c*(7.5625*(t-=(1.5/2.75))*t+.75)+b;

}else if(t<(2.5/2.75)){

return c*(7.5625*(t-=(2.25/2.75))*t+.9375)+b;

}else{

return c*(7.5625*(t-=(2.625/2.75))*t+.984375)+b;

}

}

});

}); 

  

</script>

html+css+jquery实现网站滚动条整屏滑动特效

6、代码整体结构。

html+css+jquery实现网站滚动条整屏滑动特效

7、查看效果。

html+css+jquery实现网站滚动条整屏滑动特效

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢