JQuery实现Div跟随滚动条移动不闪烁效果

移动开发
JQuery实现Div跟随滚动条移动不闪烁效果是本文要介绍的内容,主要是通过一段代码来了解JQuery所实现的一个效果,具体内容的实现来看本文详解。

JQuery实现Div跟随滚动条移动不闪烁效果是本文要介绍的内容,主要是通过一段代码来了解JQuery所实现的一个效果,具体内容的实现来看本文详解。

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  2. <html xmlns="http://www.w3.org/1999/xhtml" > 
  3. <head> 
  4.     <title>无标题页</title> 
  5.     <style type="text/css"> 
  6.     .test{  
  7.     width:100px;  
  8.     height:200px;  
  9.     position:absolute;  
  10.     top:100px;  
  11.     left:30px;  
  12.     background-color:red;  
  13.     }  
  14.     </style> 
  15.     <script type="text/javascript" src="jquery-1.3.2-vsdoc2.js"></script> 
  16.     <script type="text/javascript"> 
  17.     var timer;  
  18.     $(function(){  
  19.       $(window).scroll(function(){  
  20.         clearInterval(timer);  
  21.         var topScroll=getScroll();  
  22.         var topDiv="100px";  
  23.         var top=topScroll+parseInt(topDiv);  
  24.         timer=setInterval(function(){  
  25.             //$(".test").css("top", top+"px");  
  26.              $(".test").animate({"top":top},500);  
  27.         },500)  
  28.       })  
  29.     })  
  30.     function getScroll(){  
  31.          var bodyTop = 0;    
  32.          if (typeof window.pageYOffset != 'undefined') {    
  33.              bodyTop = window.pageYOffset;    
  34.          } else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {    
  35.              bodyTop = document.documentElement.scrollTop;    
  36.          }    
  37.          else if (typeof document.body != 'undefined') {    
  38.              bodyTop = document.body.scrollTop;    
  39.          }    
  40.          return bodyTop  
  41.     }  
  42.     </script> 
  43. </head> 
  44. <body style="width:2000px;height:8000px"> 
  45. <div class="test"></div> 
  46. </body> 
  47. </html> 

小结:JQuery实现Div跟随滚动条移动不闪烁效果的内容介绍完了,希望通过本文的学习能对你有所帮助!

责任编辑:zhaolei 来源: 互联网
相关推荐

2011-09-02 10:03:40

jQuery滚动图片

2010-09-14 10:13:53

DIV滚动条

2023-11-22 07:47:34

2010-09-09 09:47:02

DIV滚动条

2024-01-22 09:28:23

CSS前端滚动驱动

2010-09-07 09:30:25

DIV弹出jQuery

2010-09-09 11:25:55

滚动条CSS

2010-09-30 15:24:31

滚动条Javascript

2011-05-12 16:30:44

自定义滚动条

2010-09-30 15:37:29

ScrollBarJavascrip

2023-09-11 09:07:58

CSS隐藏滚动条

2022-08-15 19:23:24

macOS​Windows容器

2011-03-04 14:46:40

Ubuntu Unit

2010-07-28 11:25:08

Flex滚动条

2014-07-29 11:10:26

Ubuntu14.04小技巧

2010-08-09 15:19:29

Flex滚动条

2011-09-02 10:14:10

JQuery滚动Xslider

2012-08-10 09:46:53

jQuery

2012-05-10 14:02:46

jQuery

2012-06-14 15:49:59

Slider
点赞
收藏

51CTO技术栈公众号