最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于jQuery實(shí)現(xiàn)一個(gè)marquee無(wú)縫滾動(dòng)的插件

 更新時(shí)間:2017年03月09日 11:47:18   作者:?jiǎn)⒃吹牟柯涓? 
這篇文章主要介紹了基于jQuery實(shí)現(xiàn)一個(gè)marquee無(wú)縫滾動(dòng)的插件,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下

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

代碼如下:

/**
 * 類庫(kù)名稱:jQuery.marquee
 * 實(shí)現(xiàn)功能:基于 jquery 實(shí)現(xiàn)的 marquee 無(wú)縫滾動(dòng)插件
 * 作者主頁(yè):http://www.miaoqiyuan.cn/
 * 聯(lián)系郵箱:mqycn@126.com
 * 使用說(shuō)明: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 的問(wèn)題),非原創(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;
  };
}

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

direction,移動(dòng)方向:支持 左:left 右:right 上:top 下:bottom;

pixels,每次移動(dòng)的像素?cái)?shù)

speed,兩次移動(dòng)之前的間隔時(shí)間數(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實(shí)現(xiàn)一個(gè)marquee無(wú)縫滾動(dòng)的插件,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論

黄石市| 兖州市| 新营市| 东莞市| 化德县| 琼海市| 西宁市| 噶尔县| 大城县| 山东| 新宾| 安宁市| 左云县| 佛教| 万盛区| 巩留县| 搜索| 芦山县| 昌邑市| 健康| 临洮县| 渭南市| 宁阳县| 九龙城区| 扎鲁特旗| 扎囊县| 淄博市| 新竹县| 苍山县| 东阳市| 绵阳市| 阜新| 保康县| 高邑县| 上杭县| 合川市| 神木县| 海兴县| 泰和县| 双牌县| 大姚县|