0

画像スライダーを設定して機能させています。今必要なのは、スライダー内の要素の位置に基づいて画像を表示または非表示にすることです。

ファイアバグを見ると、次のことがわかります(liアイテムがいくつかあり、ここに1つだけ表示していることに注意してください)。

<li class="roundabout-moveable-item" style="position: absolute; left: 128px; top: 104px; width: 185.9px; height: 188.1px; opacity: 1; z-index: 145; font-size: 8.3px;">

その「左」の位置に応じて、次のようなことができるようにしたいと思います。

if left > 400px then add a class which will show image one,
if left < 300px then add a class which will show image two,
if left >= 300px and <= 400px then add a class which will show no image

すべての助けは大歓迎です。私はJQueryにかなり慣れていませんが、これまでのところ、次のことを考えています。

var left = $("li.roundabout-moveable-item").position.left;
$("li.roundabout-moveable-item").addClass("no-image");
if(left < 300px) {
    $('li.roundabout-moveable-item").addClass("image-one");
}
elseif(left > 400px) {
    $('li.roundabout-moveable-item").addClass("image-one"); 
}
else {
    $('li.roundabout-moveable-item").addClass("no-image");
}

ありがとう

4

1 に答える 1

0

コードから「px」を削除し、構文を修正するだけです。次のようなsthが必要だと思います:

var left = $(".roundabout-moveable-item").position.left;
if(left < 300) {
$(".roundabout-moveable-item").addClass("image-one");
}
else if(left > 400) {
$(".roundabout-moveable-item").addClass("image-two"); 
}
else {
$(".roundabout-moveable-item").addClass("no-image");
}
于 2012-08-06T10:30:07.583 に答える