求帮忙解答,谢谢! <html> <head> <meta charset="utf-8"> <script src="j.js"></script> <style> * { padding:0; margin:0; border:0; } .one,.two,.three { display:block; } .one { width:1px; height:1px; background-color:#f00; } .tow { background-color:#00f; } .three { background-color:#cecece; } </style> </head> <body> <!-- jquery自写滚动屏幕 --> <div class="one">one</div> <div class="two">two</div> <div class="three"></div> <script> $(document).ready(function(){ //获取当前文档的宽 高 nowWidth = $(window).width(); nowHeight = $(window).height(); //获取大的背景div one = $(".one"); two = $(".two"); three = $(".three"); <!-- alert(typeof(nowHeight)); --> //开始设置宽度高度为当前屏幕高度 one.css({"height":nowHeight,"width":nowWidth}); two.css({"height":nowHeight,"width":nowWidth}); three.css({"height":nowHeight,"width":nowWidth}); //开始监听滚动栏 //准备获取文档 var ht = $("document,html,body"); $(document).scroll(function(){ //获取当前滚动条距离文档高度 var top = $(document).scrollTop(); //如果高度 > 1 移动到第二屏 针对第一屏 if(top > 2 && top < nowHeight){ //设置滚动条高度为第一屏高度 ht.animate({"scrollTop":nowHeight},1000); } if(top > nowHeight + 2 && top < (nowHeight * 2)){ ht.animate({"scrollTop":nowHeight *2},1000); } }) }) </script> </body> </html>
林逸舟丶
MarlboroKay
相关分类