jQuery實現選中彈出窗口選擇框內容后賦值給文本框的方法
681
2024-03-20
本文實例講述了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 class="a_left"></a> <div class="bar_wrap"> <div class="bar_inner"> <ul> <li><a title="" ><img src="http://www.gimoo.net/t/1810/pic.png" alt="" /></a></li> <li><a title="" ><img src="http://www.gimoo.net/t/1810/pic.png" alt="" /></a></li> <li><a title="" ><img src="http://www.gimoo.net/t/1810/pic.png" alt="" /></a></li> <li><a title="" ><img src="http://www.gimoo.net/t/1810/pic.png" alt="" /></a></li> <li><a title="" ><img src="http://www.gimoo.net/t/1810/pic.png" alt="" /></a></li> <li><a title="" ><img src="http://www.gimoo.net/t/1810/pic.png" alt="" /></a></li> <li><a title="" ><img src="http://www.gimoo.net/t/1810/pic.png" alt="" /></a></li> <li><a title="" ><img src="http://www.gimoo.net/t/1810/pic.png" alt="" /></a></li> <li><a title="" ><img src="http://www.gimoo.net/t/1810/pic.png" alt="" /></a></li> <li><a title="" ><img src="http://www.gimoo.net/t/1810/pic.png" alt="" /></a></li> </ul> </div> </div> <a 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程序設計有所幫助。
#免責聲明#
本站[綠夏技術導航]提供的一切軟件、教程和內容信息僅限用于學習和研究目的;不得將上述內容用于商業或者非法用途,否則,一切后果請用戶自負。本站信息來自網絡收集整理,版權爭議與本站無關。您必須在下載后的24個小時之內,從您的電腦或手機中徹底刪除上述內容。如果您喜歡該程序或內容,請支持正版,購買注冊,得到更好的正版服務。我們非常重視版權問題,如有侵權請郵件[admin@lxwl520.com]與我們聯系進行刪除處理。敬請諒解!