如何使用jquery實現文字上下滾動效果
更新時間:2016年10月12日 16:40:46 作者:史洲宇
這篇文章主要介紹了jquery實現文字上下滾動效果。文字上下滾動循環(huán)顯示也是一種非常常見而且非常容易實現的文字特效。這是一種現在比較流行用的效果,用法很簡單。
實現文字上下滾動是經常用到的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插件FusionCharts繪制的2D條狀圖效果【附demo源碼】
這篇文章主要介紹了jQuery插件FusionCharts繪制的2D條狀圖效果,結合完整實例形式分析了jQuery使用FusionCharts插件繪制2D條狀圖的具體步驟與相關操作技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-05-05利用jquery和BootStrap實現動態(tài)滾動條效果
這篇文章主要介紹了利用jquery和BootStrap實現動態(tài)滾動條效果,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2018-12-12