如何使用jquery实现文字上下滚动效果
2016-10-12 16:40
1591 查看
实现文字上下滚动是经常用到的js效果,这里介绍一种上下渐隐渐出的文字展现效果!
<!DOCTYPE> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>文字滚动</title> <style type="text/css"> #sidebar{width:200px; height;500px; overflow:hidden; margin:0 auto; background:#f00; color:#fff;} #marquee{width:200px; margin:0;padding:0;} #marquee li{width:200px;height:20px; line-height:20px;} ul li{list-style:none;} </style> </head> <body> <div id="sidebar"> <ul id="marquee" class="marquee spy"> <li>11111111111111111111111111111</li> <li>22222222222222222222222222222</li> <li>33333333333333333333333333333</li> <li>44444444444444444444444444444</li> <li>55555555555555555555555555555</li> <li>asdsdssssssssssssssssssdddddd</li> <li>ggggggggggggggggggggggggggggg</li> <li>xxxxxxxxxxxxxxxxxxxxxxxxxxxxx</li> <li>11111111111111111111111111111</li> <li>22222222222222222222222222222</li> <li>33333333333333333333333333333</li> <li>44444444444444444444444444444</li> <li>55555555555555555555555555555</li> <li>asdsdssssssssssssssssssdddddd</li> <li>ggggggggggggggggggggggggggggg</li> <li>xxxxxxxxxxxxxxxxxxxxxxxxxxxxx</li> </ul> </div> </body> </html> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript"> $(function () { $('ul.spy').simpleSpy(); }); (function ($) { $.fn.simpleSpy = function (limit, interval) { limit = limit || 12;//展示数量 interval = interval || 4000; return this.each(function () { var $list = $(this), items = [], currentItem = limit, total = 0, height = $list.find('> li:first').height(); $list.find('> li').each(function () { items.push('<li>' + $(this).html() + '</li>'); }); total = items.length; $list.wrap('<div class="spyWrapper" />').parent().css({ height : height * limit }); $list.find('> li').filter(':gt(' + (limit - 1) + ')').remove(); function spy() { var $insert = $(items[currentItem]).css({ height : 0, opacity : 0, display : 'none' }).prependTo($list); $list.find('> li:last').animate({ opacity : 0}, 1000, function () { $insert.animate({ height : height }, 1000).animate({ opacity : 1 }, 1000); $(this).remove(); }); currentItem++; if (currentItem >= total) { currentItem = 0; } setTimeout(spy, interval) } spy(); }); }; })(jQuery); </script>
希望本文所述对大家学习jquery有所帮助。
您可能感兴趣的文章:
相关文章推荐
- 使用jquery实现文字滚动,鼠标悬停效果
- jquery实现文字上下滚动效果
- jquery实现文字上下循环滚动效果
- jquery实现文字的上下滚动效果
- jquery文字上下滚动的实现方法
- 使用viewpager嵌套实现上下左右滑动切换图片(IOS双向滚动翻页效果相同)
- 在asp.net中使用JQuery的SlideViewer插件实现图片的滚动效果
- Jquery:单行滚动、批量多行滚动、文字图片翻屏滚动效果的实现
- JQuery实现文字滚动效果-最简单的方法
- 如何使用jquery实现一定长度的文字/More/Less
- JQuery实现文字无缝滚动效果(Marquee插件)
- jquery文字上下滚动的实现方法
- jquery单行文字向上滚动效果的实现代码
- JQuery实现文字无缝滚动效果(Marquee插件)
- Jquery结合div+css实现文字间断停顿向上滚动效果
- 不用Margin使用jQuery实现左右滚动效果
- Delphi中的DBGrid如何实现使用鼠标滚轮上下滚动
- JQuery实现资讯上下滚动悬停效果
- jquery实现:页面上下滚动效果
- jQuery练手:仿新浪微博图片文字列表淡进淡出上下滚动效果