用于悬停在 Div 上的 jQuery 图像交换
$(document).ready(function () {
// Hide all large images except the first one
$('#imageContainer img').hide().filter(':first').show();
// Select all thumb links
$('#thumbContainer a').hover(function (event) {
// Hide all large images except for the one with the same hash as our thumb link
$('#imageContainer img').hide().filter(this.hash).show();
},
function () { } // Because the hover method has a mouseout state we need to define too
);
});
此 .js 脚本适用于将鼠标悬停在锚标记上。 但是,我希望这个函数能够在整个 div 上工作。
如何将这部分:.filter(this.hash).show();
更改
为:.filter(this.(id或唯一名称).show();
代码>
$(document).ready(function () {
// Hide all large images except the first one
$('#imageContainer img').hide().filter(':first').show();
// Select all thumb links
$('#thumbContainer a').hover(function (event) {
// Hide all large images except for the one with the same hash as our thumb link
$('#imageContainer img').hide().filter(this.hash).show();
},
function () { } // Because the hover method has a mouseout state we need to define too
);
});
This .js script works for a mouseover on an anchor tag. However, I would like this function to work on an entire div.
How do I change this part : .filter(this.hash).show();
to this : .filter(this.(id or unique name).show();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您仍然想使用哈希值,您可以使用以下代码获取它(假设
this
是您的 div):如果您想使用有关 div 的独特内容,我已使用了 div 的 id等于之前img的className。
如果你有这个html:
你可以使用这样的东西,(我将你的悬停更改为鼠标悬停,因为你只使用它):
If you still want to use the hash you could get it using this code (assuming that
this
is your div):If you want to use something unique about the div I've used the id of the div equal to the className of the img before.
If you had this html:
You could use something like this, (I changed your hover to a mouseover, since you were only using that):