您好,登錄后才能下訂單哦!
怎么在JavaScript中利用面向?qū)ο髮崿F(xiàn)一個無縫滾動輪播?針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
JavaScript面向?qū)ο蟛糠秩缦拢?br/>
function Seamless(obj) { this.obj = document.getElementById(obj); this.oXSlide = GLOBAL.Dom.getElementsByClassName('J_XSlide', this.obj)[0]; this.li = this.oXSlide.getElementsByTagName('li'); this.liTabs = GLOBAL.Dom.getElementsByClassName('tabs', this.obj)[0].getElementsByTagName('li'); this.iNow = 0; this.timer = null; this.playTime = 2000; this.init(); } Seamless.prototype = { // 初始化 init: function() { var _this = this; this.timer = setInterval(function(){ _this.autoPlay(); }, this.playTime); this.overOut(); this.tab(); }, tab: function() { var _this = this; var btn = GLOBAL.Dom.getElementsByClassName('btn', this.obj); this.oXSlide.style.width = this.li.length * this.li[0].offsetWidth + 'px'; for(var i = 0, len = this.liTabs.length; i < len; i++) { this.liTabs[i].index = i; GLOBAL.Event.addHandler(this.liTabs[i], 'mouseover', function() { _this.showItem(this.index); }); } GLOBAL.Event.addHandler(btn[0], 'click', function() { _this.moveLeft(); }); GLOBAL.Event.addHandler(btn[1], 'click', function() { _this.moveRight(); }); }, // 移入移出時,輪播暫停與開始 overOut: function() { var _this = this; GLOBAL.Event.addHandler(this.obj, 'mouseover', function() { clearInterval(_this.timer); }); GLOBAL.Event.addHandler(this.obj, 'mouseout', function() { _this.timer = setInterval(function() { _this.autoPlay(); }, _this.playTime); }); }, autoPlay: function() { this.moveRight(); }, // 選項卡 showItem:function (n) { for(var i = 0, len = this.liTabs.length; i < len; i++) { this.liTabs[i].className = 'tab'; } if(n == this.liTabs.length) { this.liTabs[0].className = 'tab cur'; } else { this.liTabs[n].className = 'tab cur'; } startMove(this.oXSlide, {'left': -n * this.li[0].offsetWidth}); }, moveLeft:function () { this.iNow--; if(this.iNow == -1) { this.oXSlide.style.left = -this.liTabs.length * this.li[0].offsetWidth + 'px'; this.iNow = this.liTabs.length - 1; } this.showItem(this.iNow); }, moveRight:function () { this.iNow++; if(this.iNow == this.li.length) { this.oXSlide.style.left = 0; this.iNow = 1; } this.showItem(this.iNow); } }; new Seamless('box');
關于怎么在JavaScript中利用面向?qū)ο髮崿F(xiàn)一個無縫滾動輪播問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業(yè)資訊頻道了解更多相關知識。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。