繁体   English   中英

独立动画相同类别的元素

[英]Animate Elements With Same Class Independantly

我有一个带有多个嵌套无序列表的无序列表。 我试图将多个嵌套的<ul></ul>独立设置为包含div中的随机位置。 我有随机位置部分,但它给每个嵌套的<ul></ul>而不是给每个位置的位置是自己的随机位置。 在下面的HTML中,我试图给每个类mapStart-second它自己独特的随机位置,在这种情况下,它们都获得相同的位置。

示例HTML

<ul id="mapStart">  

    <li id="mapStart-first">

        <ul class="mapStart-second">
            <li></li>
        </ul>

        <ul class="mapStart-second">
            <li></li>
        </ul>

    </li>

</ul>

JS / jQuery的

jQuery('#mapStart-first').one('mouseenter', function() {
    jQuery(this).find('.mapStart-second').fadeIn('slow').animate({
        top: Math.floor((Math.random()*aw_positionY)),
        left: Math.floor((Math.random()*aw_positionX)),
    });     
});

变量aw_positionsX和aw_positionY也正在动态设置并正常工作。

你需要一个循环,或者你将相同的随机值传递给每个动画:

jQuery('#mapStart-first').one('mouseenter', function() {
    jQuery(this).find('.mapStart-second').fadeIn('slow').each(function() {
        $(this).animate({
            top: Math.floor((Math.random()*aw_positionY)),
            left: Math.floor((Math.random()*aw_positionX)),
        });   
    });  
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM