後,如果我離開這個滑塊,它開始滑動像瘋了似的在網站上一段時間。如何測試這個錯誤?打開bellated.com/vyrai(測試頁面)。你可以看到大張照片。離開它一分鐘。或兩個瀏覽其他browsre標籤,當你回到這個網站,你會看到滑塊的錯誤。任何想法如何解決這一問題?的Javascript滑塊滑動想瘋了一段時間
我使用這個腳本:
<script type="text/javascript">
$(document).ready(function() {
var currentPosition = 0;
var slideWidth = 673;
var slides = $('.slide');
var numberOfSlides = slides.length;
var slideShowInterval;
var speed = 6000;
//Assign a timer, so it will run periodically
slideShowInterval = setInterval(changePosition, speed);
slides.wrapAll('<div id="slidesHolder"></div>')
slides.css({ 'float' : 'left' });
//set #slidesHolder width equal to the total width of all the slides
$('#slidesHolder').css('width', slideWidth * numberOfSlides);
manageNav(currentPosition);
//tell the buttons what to do when clicked
$('.nav').bind('click', function() {
//determine new position
currentPosition = ($(this).attr('id')=='rightNav')
? currentPosition+1 : currentPosition-1;
//hide/show controls
manageNav(currentPosition);
clearInterval(slideShowInterval);
slideShowInterval = setInterval(changePosition, speed);
moveSlide();
});
function manageNav(position) {
//hide left arrow if position is first slide
if(position==0){ $('#leftNav').hide() }
else { $('#leftNav').show() }
//hide right arrow is slide position is last slide
if(position==numberOfSlides-1){ $('#rightNav').hide() }
else { $('#rightNav').show() }
}
//changePosition: this is called when the slide is moved by the timer and NOT when the next or previous buttons are clicked
function changePosition() {
if(currentPosition == numberOfSlides - 1) {
currentPosition = 0;
manageNav(currentPosition);
} else {
currentPosition++;
manageNav(currentPosition);
}
moveSlide();
}
//moveSlide: this function moves the slide
function moveSlide() {
$('#slidesHolder').animate({'marginLeft' : slideWidth*(-currentPosition)});
}
});
</script>
HTML實現樣本:
<div id="slideshow"> <div id="slideshowWindow">
<div class="slide"><div class="slideText"> <h2 class="slideTitle">Pas mus kainos visada lanksčios!</h2> <p class="slideDes">"Tik pas mus įsigykite savo naująją vandens filtravimo sistemą palankiausiomis kainomis".</p> <p class="slideLink"><a href="http://jayreillyportraits.com"></a></p> </div><!--/slideText--> </div><!--/slide-->
<div class="slide"><div class="slideText"> <h2 class="slideTitle">Naujas prekybos salonas</h2> <p class="slideDes">"Aplankykite mus naujai atsidariusiame prekybos salone Šilalėje S. Dariaus ir S. Girėno g. 24".</p> <p class="slideLink"><a href="http://jayreillyportraits.com"></a></p> </div><!--/slideText--> </div><!--/slide-->
<div class="slide"><div class="slideText"> <h2 class="slideTitle">Ieškote galimybių partneriaujant?</h2> <p class="slideDes">"Susisiekite su mumis ir mes aptarsime abiem pusėms palankias sąlygas!".</p> <p class="slideLink"><a href="http://jayreillyportraits.com"></a></p> </div><!--/slideText--> </div><!--/slide-->
<div class="slide"><div class="slideText"> <h2 class="slideTitle">Turite klausimų?</h2> <p class="slideDes">"Susisiekite su mumis ir mūsų specialistai pasistengs atsakyti į kiekvieną jūsų užklausą.".</p> <p class="slideLink"><a href="http://jayreillyportraits.com"></a></p> </div><!--/slideText--> </div><!--/slide-->
</div></div>
其工作正常...你能更具體的什麼是瘋狂的。 – 2011-12-29 08:38:05
@RaghavBhushan你必須遵循他的指示並切換到另一個標籤,留下他的標籤在後臺運行。而且,您將不得不使用Firefox或基於WebKit的瀏覽器才能發生此行爲。 – Interrobang 2011-12-29 08:39:30
他沒有聽衆失去wondow關注怎麼可能會改變標籤影響吧.. – 2011-12-29 08:42:18