国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

基于jQuery實現一個marquee無縫滾動的插件

2024-05-06 15:09:58
字體:
來源:轉載
供稿:網友

基于jQuery,實現一個marquee無縫滾動的插件,已經發布到 git.oschina.net,演示稍后更新(更新到 http://git.oschina.net/mqycn/jQueryMarquee )。

代碼如下:

/** * 類庫名稱:jQuery.marquee * 實現功能:基于 jquery 實現的 marquee 無縫滾動插件 * 作者主頁:http://www.miaoqiyuan.cn/ * 聯系郵箱:mqycn@126.com * 使用說明:http://www.miaoqiyuan.cn/p/jquery-marquee * 最新版本:http://git.oschina.net/mqycn/jQueryMarquee*/jQuery.fn.extend({  marquee : function(opt, callback){    opt = opt || {};    opt.speed = opt.speed || 30;    opt.direction = opt.direction || 'left';    opt.pixels = opt.pixels || 2;    switch( opt.direction ){      case "left":      case "right":        opt.weight = "width";        opt.margin = "margin-left";        opt.tpl = '<table><tr><td>[TABLE]</td><td>[TABLE]</td></tr></table>';        break;      case "top":      case "bottom":        opt.weight = "height";        opt.margin = "margin-top";        opt.tpl = '<table><tr><td>[TABLE]</td></tr></tr><td>[TABLE]</td></tr></table>';        break;      default:        throw Error("[jQuery.marquee.js] Options.direction Error!");    }    switch( opt.direction ){      case "left":      case "top":        opt.addon = -1;        break;      case "right":      case "bottom":        opt.addon = 1;        break;      default:        throw Error("[jQuery.marquee.js] Options.direction Error!");    }    callback = typeof callback == "function" ? callback : function(){};    //設置寬度    $(this).each(function(){      if( this.control ){        clearInterval(this.control);      } else {        //如果第一次執行,初始化代碼        $(this)          .data(opt.weight, opt.weight == 'width' ? $(this).find("table").width() : $(this).find("table").height())          .width($(this).data(opt.weight) * 2)          .html(opt.tpl.replace(//[TABLE/]/ig, $(this).html()))          .mouseover(function(){            $(this).data("pause", true);          }).mouseout(function(){            $(this).data("pause", false);          });      }      this.control = setInterval((function(){        if( $(this).data("pause") ){          return;        }        var _margin = parseInt($(this).css(opt.margin)) + opt.addon * opt.pixels;        if( opt.addon == -1 && _margin + $(this).data(opt.weight) < 0 ){          _margin = 0;        }else if( opt.addon == 1, _margin > 0 ){          console.log(_margin < 0,$(this).data(opt.weight));          _margin = -1 * $(this).data(opt.weight);        }        $(this).css(opt.margin, _margin + "px");        callback.bind(this)();      }).bind(this), opt.speed);    });    return $(this);  }});

如果在IE9以下使用,還需要在之前增加如下代碼:

/** * IE8插件(解決 function 不支持 bind 的問題),非原創*/if (!Function.prototype.bind) {  Function.prototype.bind = function(oThis) {    if (typeof this !== "function") {      throw new TypeError("[jQuery.marquee.ie8] Caller is not a function");    }    var aArgs = Array.prototype.slice.call(arguments, 1),      fToBind = this,      fNOP = function() {},      fBound = function() {        return fToBind.apply(this instanceof fNOP && oThis ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments)));      };    fNOP.prototype = this.prototype;    fBound.prototype = new fNOP();    return fBound;  };}            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 安福县| 申扎县| 剑川县| 西吉县| 林州市| 阿拉尔市| 社旗县| 秭归县| 香格里拉县| 凉山| 郑州市| 黑山县| 大安市| 大城县| 吉木萨尔县| 白城市| 镇坪县| 湘潭市| 邮箱| 菏泽市| 湾仔区| 静宁县| 肇东市| 永州市| 深州市| 女性| 昌邑市| 樟树市| 黄山市| 南乐县| 怀来县| 鞍山市| 沿河| 射洪县| 沂源县| 麻江县| 南江县| 南江县| 广宁县| 太康县| 嫩江县|