如何使用 jQuery 将活动状态动态添加到图库缩略图
我正在使用 galleriffic 来处理我的图片库,但我在缩略图活动状态方面遇到问题。
Galleriffic 不支持图像上的活动状态 - 仅支持列表项。现在,图库将为包含缩略图的当前 LI 分配一个“选定”类,我一直在尝试使用 jQuery 来定位活动 LI 中的缩略图 ID,因此我为图像分配一个活动状态,然后将其返回到默认状态。
本质上我正在做:
$('.selected img#myImage').attr('src', 'path_to_active_state.jpg');
这有效,但是,我无法让图像恢复到默认值。我不认为 jQuery 支持在 if 语句中使用 hasClass,但如果有人知道请帮忙。欢迎任何建议。
I'm using galleriffic to handle my image gallery and I'm having a problem with the thumbnail active states.
Galleriffic doesn't have support for active states on the images - only the list items. Right now the gallery will assign a "selected" class to the current LI containing the thumbnail and I've been trying to use jQuery to target the thumbnail ID within the active LI so I assign an active state to the image and then return it to the default state.
Essentially I'm doing:
$('.selected img#myImage').attr('src', 'path_to_active_state.jpg');
Which works, however, I can't get the image to go back to the default afterward. I don't think there's jQuery support for using hasClass in an if statement, but if someone knows please help out. Any advice is welcomed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试一下
:not
选择器吗?您当前正在执行此操作以获取选定的图像:尝试执行此操作以获取未选定的图像:
Could you try the
:not
selector? You're currently doing this to get the selected image:Try doing this to get the unselected image:
您可以向活动图像添加一个类,以便稍后可以识别它。
因此
,当在示例中突出显示另一个缩略图时
$('.selected img#myImage')
似乎暗示您对所有缩略图使用相同的 ID (#myImage
)。 Id 在 DOM 中应该是唯一的。You could add a class to the active image, so that you can identify it later..
so
and when highlighting another thumbnail
also in your example
$('.selected img#myImage')
seems to imply that you use the same id for all thumbnails (#myImage
). Id's should be unique inside the DOM..