Py学习  »  Jquery

对单独出现的元素应用jquery函数

Juárez • 5 年前 • 1519 次点击  

我在用 jGravity 在加载页上。页面在页面加载期间加载不同的div,我想对每个出现的div应用jgravity,但只应用一次。这是我目前掌握的代码,但它每次都对每个div.bubble应用jgravity,所以它会把所有事情都搞砸。

 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 ++;

提前谢谢你

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/41144
 
1519 次点击  
文章 [ 1 ]  |  最新文章 5 年前
Matt
Reply   •   1 楼
Matt    6 年前

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

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 伪类。