javascript - 当其他 div 具有相同的类时,如何要求 jquery 应用于一个 div

标签 javascript jquery html css

这里的问题是,当我将鼠标悬停在特定的 div 上时,jquery 脚本将应用于具有相同类的每个 div。我希望该脚本仅适用于悬停元素,即使其他 div 具有相同的类也是如此。为了方便起见,我没有在其中添加 css ID。 这是我的 jQuery 代码:

jQuery(".enprod_grille .isotope-container").hover(function() {
    // do this on hover
    jQuery('.enprod_grille .post-thumb').animate({
      'marginRight': '0px',
      'opacity': '0.4'
    }, 'fast');
    jQuery('.enprod_grille .post-title').animate({
       'paddingLeft': '0px',
       'opacity': '1'
    }, 'fast');
    jQuery('.enprod_grille .entry-content').animate({
       'paddingLeft': '0px',
       'opacity': '1'
    }, 'fast');
},function() {
    // do this on hover out
    jQuery('.enprod_grille .post-thumb').animate({
       'marginRight': '45px',
       'opacity': '1'
    }, 'fast');
    jQuery('.enprod_grille .post-title').animate({
       'paddingLeft': '20px',
       'opacity': '0'
    }, 'fast');
    jQuery('.enprod_grille .entry-content').animate({
       'paddingLeft': '20px',
       'opacity': '0'
    }, 'fast');
});

这是网站的链接,它出现在右下角的“En production”栏中:http://mwww.fr/fullhouse/?lang=fr

最佳答案

使用 this 定位当前 div,例如:

jQuery(".enprod_grille .isotope-container").hover(function() {
    // do this on hover
    jQuery(this).find('.post-thumb').animate({
        'marginRight': '0px',
        'opacity': '0.4'
    }, 'fast');
    jQuery(this).find('.post-title').animate({
        'paddingLeft': '0px',
        'opacity': '1'
    }, 'fast');
    jQuery(this).find('.entry-content').animate({
        'paddingLeft': '0px',
        'opacity': '1'
    }, 'fast');
}, function() {
    // do this on hover out
    jQuery(this).find('.post-thumb').animate({
        'marginRight': '45px',
        'opacity': '1'
    }, 'fast');
    jQuery(this).find('.post-title').animate({
        'paddingLeft': '20px',
        'opacity': '0'
    }, 'fast');
    jQuery(this).find('.entry-content').animate({
        'paddingLeft': '20px',
        'opacity': '0'
    }, 'fast');
});

关于javascript - 当其他 div 具有相同的类时,如何要求 jquery 应用于一个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30051928/

相关文章:

HTML 页面中 JavaScript 的执行顺序

jquery - jquery 中的隐藏()

css - 在 div HTML/CSS 中对齐 div

html - 支持更小的设备宽度

javascript - ngOptions 在我的选择元素中没有显示任何选项

javascript - Node.js 中的 promise 回调

javascript - 如何在 Rails 中的不同文件中使用我的 javascript 函数

javascript - 如何为 Angular JS Auto Complete 提供固定高度?

javascript - 视频标签有问题。视频通话结束后海报不可见

javascript - 通过单击背景或空间来展开组空间