私は何かひどく間違ったことをしており、その解決策を見つけることができません。
状況: 製品ごとに複数の見積もりがある製品が多数あります。それらの引用はdivで自動的にスクロールします。スクロールが最後の引用に達すると、最初の引用に戻ります。
機能: この関数は基本的に 1 つの div に適用された場合に機能しますが、複数の div に適用された場合、最初の 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 div に適用)
以下を変更する場合:
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でのみです。