首页 > 语言 > JavaScript > 正文

jquery滚动特效集锦 jquery滚动特效大全

2024-05-06 16:21:09
字体:大 中 小
来源:转载
供稿:网友

本文给大家汇总介绍的是jquery单行滚动、批量多行滚动、文字图片翻屏滚动效果代码,都是分厂常用的一些文字以及图文的无缝滚动特效,希望能够对大家熟悉jQuery有所帮助。

jquery单行滚动、批量多行滚动、文字图片翻屏滚动效果代码,需要的朋友可以参考下。

以下代码,运行后,需要刷新下,才能加载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. <meta http-equiv="Content-Type" c /> 
  5. <title>无标题文档</title> 
  6. <style type="text/css"> 
  7. ul,li{margin:0;padding:0} 
  8. #scrollDiv{width:300px;height:25px;line-height:25px;border:#ccc 1px solid;overflow:hidden} 
  9. #scrollDiv li{height:25px;padding-left:10px;} 
  10. </style> 
  11. <script src="http://www.vevb.com/jslib/jquery/jquery14.js" type="text/javascript"></script> 
  12. <script type="text/javascript"> 
  13. function AutoScroll(obj){ 
  14. $(obj).find("ul:first").animate({ 
  15. marginTop:"-25px" 
  16. },500,function(){ 
  17. $(this).css({marginTop:"0px"}).find("li:first").appendTo(this); 
  18. }); 
  19. } 
  20. $(document).ready(function(){ 
  21. setInterval('AutoScroll("#scrollDiv")',1000) 
  22. }); 
  23. </script> 
  24. </head> 
  25. <body> 
  26. <div id="scrollDiv"> 
  27. <ul> 
  28. <li>百度 www.baidu.com</li> 
  29. <li>武林网 www.vevb.com</li> 
  30. <li>这是公告标题的第三行</li> 
  31. <li>这是公告标题的第四行</li> 
  32. <li>这是公告标题的第五行</li> 
  33. <li>这是公告标题的第六行</li> 
  34. <li>这是公告标题的第七行</li> 
  35. <li>这是公告标题的第八行</li> 
  36. </ul> 
  37. </div> 
  38. </body> 
  39. </html> 

二,多行滚动效果

 

 
  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. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
  5. <title>无标题文档</title> 
  6. <style type="text/css"> 
  7. ul,li{margin:0;padding:0} 
  8. #scrollDiv{width:300px;height:100px;min-height:25px;line-height:25px;border:#ccc 1px solid;overflow:hidden} 
  9. #scrollDiv li{height:25px;padding-left:10px;} 
  10. </style> 
  11. <script src="http://www.vevb.com/jslib/jquery/jquery14.js" type="text/javascript"></script> 
  12. <script type="text/javascript"> 
  13. //滚动插件 
  14. (function($){ 
  15. $.fn.extend({ 
  16. Scroll:function(opt,callback){ 
  17. //参数初始化 
  18. if(!opt) var opt={}; 
  19. var _this=this.eq(0).find("ul:first"); 
  20. var lineH=_this.find("li:first").height(), //获取行高 
  21. line=opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10), //每次滚动的行数,默认为一屏,即父容器高度 
  22. speed=opt.speed?parseInt(opt.speed,10):500, //卷动速度,数值越大,速度越慢(毫秒) 
  23. timer=opt.timer?parseInt(opt.timer,10):3000; //滚动的时间间隔(毫秒) 
  24. if(line==0) line=1; 
  25. var upHeight=0-line*lineH; 
  26. //滚动函数 
  27. scrollUp=function(){ 
  28. _this.animate({ 
  29. marginTop:upHeight 
  30. },speed,function(){ 
  31. for(i=1;i<=line;i++){ 
  32. _this.find("li:first").appendTo(_this); 
  33. } 
  34. _this.css({marginTop:0}); 
  35. }); 
  36. } 
  37. //鼠标事件绑定 
  38. _this.hover(function(){ 
  39. clearInterval(timerID); 
  40. },function(){ 
  41. timerID=setInterval("scrollUp()",timer); 
  42. }).mouseout(); 
  43. } 
  44. }) 
  45. })(jQuery); 
  46. $(document).ready(function(){ 
  47. $("#scrollDiv").Scroll({line:4,speed:500,timer:1000}); 
  48. }); 
  49. </script> 
  50. </head> 
  51. <body> 
  52. <p>多行滚动演示:</p> 
  53. <div id="scrollDiv"> 
  54. <ul> 
  55. <li>百度 www.baidu.com</li> 
  56. <li>武林网 www.vevb.com</li> 
  57. <li>这是公告标题的第三行</li> 
  58. <li>这是公告标题的第四行</li> 
  59. <li>这是公告标题的第五行</li> 
  60. <li>这是公告标题的第六行</li> 
  61. <li>这是公告标题的第七行</li> 
  62. <li>这是公告标题的第八行</li> 
  63. </ul> 
  64. </div> 
  65. </body> 
  66. </html> 

三、可控制向前向后的多行滚动

 

 
  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. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
  5. <title>无标题文档</title> 
  6. <style type="text/css"> 
  7. ul,li{margin:0;padding:0} 
  8. #scrollDiv{width:300px;height:100px;min-height:25px;line-height:25px;border:#ccc 1px solid;overflow:hidden} 
  9. #scrollDiv li{height:25px;padding-left:10px;} 
  10. </style> 
  11. <script src="http://www.vevb.com/jslib/jquery/jquery14.js" type="text/javascript"></script> 
  12. <script type="text/javascript"> 
  13. (function($){ 
  14. $.fn.extend({ 
  15. Scroll:function(opt,callback){ 
  16. //参数初始化 
  17. if(!opt) var opt={}; 
  18. var _btnUp = $("#"+ opt.up);//Shawphy:向上按钮 
  19. var _btnDown = $("#"+ opt.down);//Shawphy:向下按钮 
  20. var timerID; 
  21. var _this=this.eq(0).find("ul:first"); 
  22. var lineH=_this.find("li:first").height(), //获取行高 
  23. line=opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10), //每次滚动的行数,默认为一屏,即父容器高度 
  24. speed=opt.speed?parseInt(opt.speed,10):500; //卷动速度,数值越大,速度越慢(毫秒) 
  25. timer=opt.timer //?parseInt(opt.timer,10):3000; //滚动的时间间隔(毫秒) 
  26. if(line==0) line=1; 
  27. var upHeight=0-line*lineH; 
  28. //滚动函数 
  29. var scrollUp=function(){ 
  30. _btnUp.unbind("click",scrollUp); //Shawphy:取消向上按钮的函数绑定 
  31. _this.animate({ 
  32. marginTop:upHeight 
  33. },speed,function(){ 
  34. for(i=1;i<=line;i++){ 
  35. _this.find("li:first").appendTo(_this); 
  36. } 
  37. _this.css({marginTop:0}); 
  38. _btnUp.bind("click",scrollUp); //Shawphy:绑定向上按钮的点击事件 
  39. }); 
  40. } 
  41. //Shawphy:向下翻页函数 
  42. var scrollDown=function(){ 
  43. _btnDown.unbind("click",scrollDown); 
  44. for(i=1;i<=line;i++){ 
  45. _this.find("li:last").show().prependTo(_this); 
  46. } 
  47. _this.css({marginTop:upHeight}); 
  48. _this.animate({ 
  49. marginTop:0 
  50. },speed,function(){ 
  51. _btnDown.bind("click",scrollDown); 
  52. }); 
  53. } 
  54. //Shawphy:自动播放 
  55. var autoPlay = function(){ 
  56. if(timer)timerID = window.setInterval(scrollUp,timer); 
  57. }; 
  58. var autoStop = function(){ 
  59. if(timer)window.clearInterval(timerID); 
  60. }; 
  61. //鼠标事件绑定 
  62. _this.hover(autoStop,autoPlay).mouseout(); 
  63. _btnUp.css("cursor","pointer").click( scrollUp ).hover(autoStop,autoPlay);//Shawphy:向上向下鼠标事件绑定 
  64. _btnDown.css("cursor","pointer").click( scrollDown ).hover(autoStop,autoPlay); 
  65. } 
  66. }) 
  67. })(jQuery); 
  68. $(document).ready(function(){ 
  69. $("#scrollDiv").Scroll({line:4,speed:500,timer:1000,up:"btn1",down:"btn2"}); 
  70. }); 
  71. </script> 
  72. </head> 
  73. <body> 
  74. <p>多行滚动演示:</p> 
  75. <div id="scrollDiv"> 
  76. <ul> 
  77. <li>这是公告标题的第一行</li> 
  78. <li>这是公告标题的第二行</li> 
  79. <li>这是公告标题的第三行</li> 
  80. <li>这是公告标题的第四行</li> 
  81. <li>这是公告标题的第五行</li> 
  82. <li>这是公告标题的第六行</li> 
  83. <li>这是公告标题的第七行</li> 
  84. <li>这是公告标题的第八行</li> 
  85. </ul> 
  86. </div> 
  87. <span id="btn1">向前</span> <span id="btn2">向后</span> 
  88. </body> 
  89. </html> 

以上所述就是本文的全部内容了,希望大家能够喜欢。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选