我正在做一些非常錯誤的事情,只是找不到解決方案。多個div類上的相同函數不起作用
情況: 我有許多產品,每個產品的報價數。那些報價自動滾動分區。如果滾動到達最後一個報價是回滾到第一個。
什麼工作: 當它在1個格應用的功能基本上是工作的,但是當多個DIV應用它並不能回滾到前一個或不停不休滾動。
這是我這個寫的函數:
function quoteSlide(divname){
$total = ($(divname+" > div").size())
$width = $total * 160;
$(divname).css('width', ($width));
console.log ($totalleft *-1);
if ($width - 160 > $totalleft *-1){
$currentleft = $(divname).css('left');
$step = -160;
$totalleft = parseInt($currentleft)+$step;
}else{
$totalleft = 0;
}
$(divname).animate(
{
left: $totalleft
}, // what we are animating
'slow', // how fast we are animating
'swing', // the type of easing
function() { // the callback
});
}
它正在像執行:結合quoteSlide('#quotecontainer_1');
與setInterval的,因此自動保持滾動。
這是jsFiddle它出錯了(所以應用於多於一個div)http://jsfiddle.net/FsrbZ/。 這是一切順利的jsFiddle。 (適用於1個格)
當改變如下:
quoteSlide('#quotecontainer_1');
quoteSlide('#quotecontainer_2');
setInterval(function() {
quoteSlide('#quotecontainer_1');
quoteSlide('#quotecontainer_2');
}, 3400);
到
quoteSlide('#quotecontainer_1');
setInterval(function() {
quoteSlide('#quotecontainer_1');
}, 3400);
它的工作...但僅限於1個quotecontainer。
a nd HTML代碼,它在哪裏? –
你可以在jsFiddle找到它。問題不在於HTML(我認爲;-)),這就是爲什麼我沒有在這裏發佈它。 –