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

首頁 > 編程 > JavaScript > 正文

jQuery實現的無縫廣告圖片左右滾動功能詳解

2019-11-19 18:17:12
字體:
來源:轉載
供稿:網友

本文實例講述了jQuery實現的無縫廣告圖片左右滾動功能。分享給大家供大家參考,具體如下:

先是寫了一個此功能的jQuery插件,但是一時寫不出如何使用鼠標進行滾動方向的切換,于是又寫了另一個可以實現切換的版本...

原理:

1.把滾動的內容復制2份放到原內容左右,這樣無論向左右滾動都不會出現斷掉的情況

2.改變內容樣式的left值實現滾動效果,向左或向右滾動一個內容的長度后,還原并繼續滾動,這樣看起來就像無縫一直滾動的樣子了(視覺上的效果,^_^)

3.鼠標放上去則clearInterval,移開后繼續setInterval

4.移動效果寫成一個方法,切換方向時調用一次即可

<style>* { margin:0; padding:0;}ul { list-style:none; margin:0; padding:0;}img { border:none;}.bar {  margin:0 auto;  width:800px; height:48px; overflow:hidden;  line-height:48px; border:2px solid #EEE;}.bar a.a_left,.bar a.a_right{  float:left;  width:11px; height:48px;  background:url(a_left.png) no-repeat left center;}.bar a.a_right { float:right; background-image:url(a_right.png);}.bar_wrap { float:left; position:relative; width:776px; height:48px; white-space:nowrap; overflow:hidden;}.bar_inner { position:relative; height:48px; line-height:48px; left:0; width:2880px; white-space:nowrap;}.bar_inner ul { height:48px; overflow:hidden; float:left; width:960px;}.bar_inner ul li{ float:left;}.bar_inner ul li a{ padding:0 16px; display:block; height:48px; line-height:48px;}</style>
<body><div class="bar">  <a href="#" class="a_left"></a>  <div class="bar_wrap">  <div class="bar_inner">    <ul>      <li><a href="#" title="" ><img src="pic.png" alt="" /></a></li>      <li><a href="#" title="" ><img src="pic.png" alt="" /></a></li>      <li><a href="#" title="" ><img src="pic.png" alt="" /></a></li>      <li><a href="#" title="" ><img src="pic.png" alt="" /></a></li>      <li><a href="#" title="" ><img src="pic.png" alt="" /></a></li>      <li><a href="#" title="" ><img src="pic.png" alt="" /></a></li>      <li><a href="#" title="" ><img src="pic.png" alt="" /></a></li>      <li><a href="#" title="" ><img src="pic.png" alt="" /></a></li>      <li><a href="#" title="" ><img src="pic.png" alt="" /></a></li>      <li><a href="#" title="" ><img src="pic.png" alt="" /></a></li>    </ul>  </div>  </div>  <a href="#" class="a_right"></a></div>
var scrollBar = function(){  this.step = 14;  this.speed = 100;  this.inner = $(".bar_inner");  this.wrap = $(".bar_wrap");  this.ini = 0;  this.pos = "l";  this.s ;  }scrollBar.prototype = {  check : function(){    return this.inner.width() < this.wrap.width() ? false : true;    } ,  init : function(){    if( this.check() ){      this.inner        .html( this.inner.html() + this.inner.html() + this.inner.html() )        .css("left",- this.inner.width()/3 + "px");      }    },  run : function(pos){    if (! this.check()){ return;}    if( this.ini == 0) {this.init();}    this.ini = 1;    this.pos = pos;    var that = this;    var f = function(){      if(that.pos == "l"){        var l = parseInt( that.inner.css("left") ) - that.step;        that.inner.css("left",l + "px");        //console.log(l);        if ( parseInt(that.inner.css("left")) <= -( that.inner.width()/ 3 * 2) ){          that.inner.css("left",- that.inner.width() /3 + "px");          }        }      else {        var l = parseInt( that.inner.css("left") ) + that.step;        that.inner.css("left",l + "px");        //console.log( l );        if( parseInt(that.inner.css("left")) >= 0 ){          that.inner.css("left", - that.inner.width()/3 + "px");          }        }      }    if(this.s) {clearInterval(that.s);};    this.s = setInterval( f ,that.speed);    that.inner.hover(      function(){ clearInterval(that.s);},      function(){clearInterval(that.s); that.s = setInterval( f ,that.speed); }      )    }  }var s = new scrollBar();s.run("r");$(".a_left").mouseover(function(){  clearInterval( s.s);  s.run("l");  })$(".a_right").mouseover(function(){     clearInterval( s.s);  s.run("r");})

更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery圖片操作技巧大全》、《jQuery切換特效與技巧總結》、《jQuery拖拽特效與技巧總結》、《jQuery擴展技巧總結》、《jQuery常見經典特效匯總》、《jQuery動畫與特效用法總結》、《jquery選擇器用法總結》及《jQuery常用插件及用法總結

希望本文所述對大家jQuery程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 莱阳市| 隆子县| 修文县| 台北市| 苍梧县| 惠来县| 会昌县| 虹口区| 若尔盖县| 兴宁市| 富蕴县| 吉林市| 扬州市| 泌阳县| 石棉县| 宜昌市| 武冈市| 孟津县| 潜山县| 右玉县| 定边县| 昭平县| 永寿县| 公安县| 浠水县| 荔波县| 龙井市| 中方县| 弥渡县| 波密县| 隆子县| 兴义市| 宜宾市| 萍乡市| 台中市| 沙田区| 平武县| 栾川县| 临洮县| 冕宁县| 自贡市|