社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Jquery

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

Juárez • 4 年前 • 784 次点击  

我在用 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
 
784 次点击  
文章 [ 1 ]  |  最新文章 4 年前
Matt
Reply   •   1 楼
Matt    5 年前

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

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