根据位置显示或隐藏图像(图像滑块)

时间:2012-08-06 10:20:18

标签: javascript jquery image slider

我有一个图像滑块设置和工作,我现在需要的是根据滑块内元素的位置显示或隐藏图像。

看着萤火虫,我可以看到以下内容(请注意有几件礼品,我只是在这里展示一件):

<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");
}

由于

1 个答案:

答案 0 :(得分:0)

只需从代码中删除“px”并更正语法即可。 我想你需要这样:

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");
}