文字无缝滚动效果代码
可以用于新闻公告等,鼠标经过暂停
XML/HTML Code
- <div class="box">
- <div class="bcon">
- <h1><b>News</b></h1>
- <!-- 代码开始 -->
- <div class="list_lh">
- <ul>
- <li>
- <p><a href="" target="_blank">1000000</a></p>
- <p><a href="" target="_blank" class="a_blue">freejs.net</a><span>17:28:05</span></p>
- </li>
- <li>
- <p><a href="" target="_blank">2000000</a></p>
- <p><a href="" target="_blank" class="a_blue">freejs.net</a><span>17:28:05</span></p>
- </li>
- <li>
- <p><a href="" target="_blank">3000000</a></p>
- <p><a href="" target="_blank" class="a_blue">freejs.net</a><span>17:28:05</span></p>
- </li>
- <li>
- <p><a href="" target="_blank">4000000</a></p>
- <p><a href="" target="_blank" class="a_blue">freejs.net</a><span>17:28:05</span></p>
- </li>
- <li>
- <p><a href="" target="_blank">5000000</a></p>
- <p><a href="" target="_blank" class="a_blue">freejs.net</a><span>17:28:05</span></p>
- </li>
- <li>
- <p><a href="" target="_blank">6000000</a></p>
- <p><a href="" target="_blank" class="a_blue">freejs.net</a><span>17:28:05</span></p>
- </li>
- <li>
- <p><a href="" target="_blank">7000000</a></p>
- <p><a href="" target="_blank" class="a_blue">freejs.net</a><span>17:28:05</span></p>
- </li>
- <li>
- <p><a href="" target="_blank">8000000</a></p>
- <p><a href="" target="_blank" class="a_blue">freejs.net</a><span>17:28:05</span></p>
- </li>
- <li>
- <p><a href="" target="_blank">9000000</a></p>
- <p><a href="" target="_blank" class="a_blue">freejs.net</a><span>17:28:05</span></p>
- </li>
- <li>
- <p><a href="" target="_blank">1000000</a></p>
- <p><a href="" target="_blank" class="a_blue">freejs.net</a><span>17:28:05</span></p>
- </li>
- <li>
- <p><a href="" target="_blank">1100000</a></p>
- <p><a href="" target="_blank" class="a_blue">freejs.net</a><span>17:28:05</span></p>
- </li>
- <li>
- <p><a href="" target="_blank">1200000</a></p>
- <p><a href="" target="_blank" class="a_blue">freejs.net</a><span>17:28:05</span></p>
- </li>
- </ul>
- </div>
- <!-- 代码结束 -->
- </div>
- </div>
JavaScript Code
- // JavaScript Document
- (function($){
- $.fn.myScroll = function(options){
- //默认配置
- var defaults = {
- speed:40, //滚动速度,值越大速度越慢
- rowHeight:24 //每行的高度
- };
- var opts = $.extend({}, defaults, options),intId = [];
- function marquee(obj, step){
- obj.find("ul").animate({
- marginTop: '-=1'
- },0,function(){
- var s = Math.abs(parseInt($(this).css("margin-top")));
- if(s >= step){
- $(this).find("li").slice(0, 1).appendTo($(this));
- $(this).css("margin-top", 0);
- }
- });
- }
- this.each(function(i){
- var sh = opts["rowHeight"],speed = opts["speed"],_this = $(this);
- intId[i] = setInterval(function(){
- if(_this.find("ul").height()<=_this.height()){
- clearInterval(intId[i]);
- }else{
- marquee(_this, sh);
- }
- }, speed);
- _this.hover(function(){
- clearInterval(intId[i]);
- },function(){
- intId[i] = setInterval(function(){
- if(_this.find("ul").height()<=_this.height()){
- clearInterval(intId[i]);
- }else{
- marquee(_this, sh);
- }
- }, speed);
- });
- });
- }
- })(jQuery);
原文地址:http://www.freejs.net/article_jquerywenzi_696.html