使用jQuery链接将鼠标悬停到img标记

make hover to img tag with jQuery chaining

本文关键字:img 标记 悬停 鼠标 jQuery 链接 使用      更新时间:2024-05-28

我目前正在尝试。但它不起作用。。

$('.hover-button').hover(function() {
    $('.section.coolClass img').addClass('.hoverclass');
});

因为假设它附加到img标记并失败。关于如何实现这一点,有什么想法吗?

。悬停时,需要删除该类。。

此外,注意:我正在努力实现这一点:

section.coolClass img:hover {
  transform: scale(1.2); z-index: 3; cursor: pointer;
}

您正在使用css,而您应该使用toggleClass。像这样:

$('.hover-button').hover(function() {
    $('.section.coolClass img').toggleClass('hoverclass');
});

css用于将内联样式添加到元素中。如果要向元素添加/删除类,请使用addClassremoveClasstoggleClass。也不包括.

试试这个:

$('.hover-button').hover(function() {
    $('.section.coolClass img').toggleClass('hoverclass');
});