欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于jQuery實現(xiàn)一個marquee無縫滾動的插件

 更新時間:2017年03月09日 11:47:18   作者:啟源的部落格  
這篇文章主要介紹了基于jQuery實現(xiàn)一個marquee無縫滾動的插件,非常不錯,具有參考借鑒價值,需要的朋友可以參考下

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

代碼如下:

/**
 * 類庫名稱:jQuery.marquee
 * 實現(xiàn)功能:基于 jquery 實現(xiàn)的 marquee 無縫滾動插件
 * 作者主頁:http://www.miaoqiyuan.cn/
 * 聯(lián)系郵箱: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(){};
    //設(shè)置寬度
    $(this).each(function(){
      if( this.control ){
        clearInterval(this.control);
      } else {
        //如果第一次執(zhí)行,初始化代碼
        $(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 的問題),非原創(chuàng)
*/
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;
  };
}

一共有三個可選參數(shù),一個回調(diào)方法。

direction,移動方向:支持 左:left 右:right 上:top 下:bottom;

pixels,每次移動的像素數(shù)

speed,兩次移動之前的間隔時間數(shù)(毫秒)

調(diào)用方法如下:

$("scroll-a").marquee();
$("scroll-b").marquee({direction:'top'});
$("scroll-c").marquee({direction:'top',pixels:2,speed:30});
$("scroll-d").marquee({direction:"top",pixels:2,speed:30}, function(){
  console.log("執(zhí)行了一次");
});

以上所述是小編給大家介紹的基于jQuery實現(xiàn)一個marquee無縫滾動的插件,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • 使用jQuery處理AJAX請求的基礎(chǔ)學(xué)習(xí)教程

    使用jQuery處理AJAX請求的基礎(chǔ)學(xué)習(xí)教程

    這篇文章主要介紹了使用jQuery處理AJAX請求的基礎(chǔ)學(xué)習(xí)教程,除此之外還引申了鏈?zhǔn)教幚硎录卣{(diào)的寫法,由淺入深非常值得借鑒,需要的朋友可以參考下
    2016-05-05
  • JQuery控制Radio選中方法分析

    JQuery控制Radio選中方法分析

    這篇文章主要介紹了JQuery控制Radio選中方法,涉及jQuery表單操作及鼠標(biāo)事件響應(yīng)的方法,需要的朋友可以參考下
    2015-05-05
  • JQuery選擇器詳解

    JQuery選擇器詳解

    這篇文章主要為大家介紹了JQuery選擇器,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2021-12-12
  • jQuery實現(xiàn)的圖文高亮滾動切換特效實例

    jQuery實現(xiàn)的圖文高亮滾動切換特效實例

    這篇文章主要介紹了jQuery實現(xiàn)的圖文高亮滾動切換特效,涉及jquery基于鼠標(biāo)事件針對頁面元素遍歷與動態(tài)操作的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-08-08
  • jQuery EasyUI 組件加上“清除”功能實例詳解

    jQuery EasyUI 組件加上“清除”功能實例詳解

    在使用 EasyUI 各表單組件時,尤其是使用 ComboBox(下拉列表框)、DateBox(日期輸入框)、DateTimeBox(日期時間輸入框)這三個組件時,經(jīng)常會遇到下拉框或日期只允許選擇、不允許手動輸入功能,怎么解決呢,下面小編給大家分享解決方案,一起看看吧
    2017-04-04
  • Query中click(),bind(),live(),delegate()的區(qū)別

    Query中click(),bind(),live(),delegate()的區(qū)別

    這篇文章主要介紹了Query中click(),bind(),live(),delegate()之間的區(qū)別。需要的朋友可以過來參考下,希望對大家有所幫助
    2013-11-11
  • JQuery復(fù)制DOM節(jié)點(diǎn)的方法

    JQuery復(fù)制DOM節(jié)點(diǎn)的方法

    這篇文章主要介紹了JQuery復(fù)制DOM節(jié)點(diǎn)的方法,涉及jQuery中clone與appendTo方法的使用技巧,需要的朋友可以參考下
    2015-06-06
  • jQuery實現(xiàn)的原圖對比窗簾效果

    jQuery實現(xiàn)的原圖對比窗簾效果

    這篇文章主要介紹了jQuery實現(xiàn)的原圖對比窗簾效果,需要的朋友可以參考下
    2014-06-06
  • Jquery AutoComplete自動完成 的使用方法實例

    Jquery AutoComplete自動完成 的使用方法實例

    jQuery的Autocomplete(自動完成、自動填充)插件有不少,但比較下來我感覺,還是bassistance.de的JQuery Autocomplete plugin比較強(qiáng)大,我們就來寫一些代碼感受一下。
    2010-03-03
  • jQuery修改CSS偽元素屬性的方法

    jQuery修改CSS偽元素屬性的方法

    CSS偽元素不是DOM元素,因此你無法直接選擇到它們。下面與大家分享兩種不錯的修改方法,需要的朋友可以參考下
    2014-07-07

最新評論