我有一个图像滑块设置和工作,我现在需要的是显示或隐藏基于滑块内元素位置的图像。在Firebug根据位置显示或隐藏图像(图像滑块)
看,我可以看到以下内容(请注意,有几个里的项目,我只是显示一个在这里):
<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");
}
感谢
http://jsfiddle.net/XZXPh/检查此链接,并把您的影像检查你的代码。 – 2012-08-06 10:37:32
好吧,所以我更新了jsfiddle,似乎唯一添加的类是.no-image类。 这将应用于所有列表项目,因此清单项目的“左”位置显然未被拾取。 任何人都可以提供任何想法为什么? – Johnny 2012-08-06 11:16:29
好的,我可以看到,如果我添加一个警报(左);到我的代码,它显示为未定义。 – Johnny 2012-08-06 11:32:26