jquery - 将 jQuery 函数应用于单独出现的元素

标签 jquery this

我正在使用jGravity在加载页面上。页面在页面加载期间加载不同的 div,我想将 jGravity 应用于每个出现的 div,但仅一次。这是我到目前为止的代码,但它每次都将 jGravity 应用于每个 div.bubble,所以它搞乱了一切。

 function showDiv() {
     if(counter == 0 ) { counter ++; return; }
     $('#whatsapp').find('#bubble-' + counter).show().jGravity({ 
        target: 'div.bubble',
        ignoreClass: 'ignoreMe',
        weight: 25, 
        depth: 5, 
        drag: true 
    });
     counter ++;

提前谢谢

最佳答案

我目前无法测试,但我认为这可以满足您的需求:

function showDiv() {
    if(counter == 0 ) { counter ++; return; }
    $('#whatsapp').find('#bubble-' + counter + ':not(.ignoreMe)').addClass('ignoreMe').show().jGravity({ 
        target: 'div.bubble',
        ignoreClass: 'ignoreMe',
        weight: 25, 
        depth: 5, 
        drag: true 
    });
    counter ++

它会向每个项目添加一个类 ignoreMe ,然后使用 :not 忽略具有该类的项目。伪类。

关于jquery - 将 jQuery 函数应用于单独出现的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53211571/

相关文章:

javascript - 如何在asp.net中使用javascript显示和上传图像?

javascript - Sequelize 实例方法不起作用?

javascript - 为什么用 'this' 填充的 JavaScript var 会随着 'this' 的变化而变化?

c++ - 构造函数内部 "this"的 dynamic_cast

javascript - 添加另一个类后,jQuery 不再为每个类找到 dom

javascript - form_for 和 onsubmit() jQuery 函数

javascript - 将日期和时间格式化为 DTG

javascript - 克隆 div 并更改属性

javascript - 这又迷路了

javascript - 在全局上下文中使用类方法时, `this` 为未定义