如何使用jquery实现文字上下滚动效果
2019/6/27 21:43:11
本文主要是介绍如何使用jquery实现文字上下滚动效果,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
实现文字上下滚动是经常用到的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实现文字上下滚动效果的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-20Vue资料入门教程:从零开始学习Vue.js
- 2024-09-20Vuex4入门教程:轻松掌握Vue状态管理
- 2024-09-20Element-Plus入门指南:轻松构建美观的Vue组件
- 2024-09-20VueRouter4入门教程:轻松掌握Vue路由
- 2024-09-20Vuex4入门教程:轻松掌握Vue状态管理
- 2024-09-20Vue3课程:新手入门与初级教程详解
- 2024-09-20Vue3课程:新手入门到初级实战指南
- 2024-09-20Vuex4学习:一步一步搭建你的第一个Vuex状态管理库
- 2024-09-19Vue项目中实现TagsView标签栏导航的简单教程
- 2024-09-19Vue3入门指南:基础教程与实战项目