English 中文(简体)
jquery animate: change the elements s opcity one by one
原标题:jquery animate: change the element s opacity one by one

任何想法,如何将每个要素的不透明性与不超过16个目标/要素联系起来?

这将共同改变各要素的不透明性,

$( .block-item ).animate({
        opacity:0
    },500);

查询here

但是,我希望这种不透明性会相互改变。 直至第16项内容时,这一点将停止。

页: 1

<div id="parent_container">

<div class="block-item">1</div>
<div class="block-item">2</div>
<div class="block-item">3</div>
<div class="block-item">4</div>
<div class="block-item">5</div>
<div class="block-item">6</div>
<div class="block-item">7</div>
<div class="block-item">8</div>
<div class="block-item">9</div>
<div class="block-item">10</div>
<div class="block-item">11</div>
<div class="block-item">12</div>
<div class="block-item">13</div>
<div class="block-item">14</div>
<div class="block-item">15</div>
<div class="block-item">16</div>
<div class="block-item">17</div>
<div class="block-item">18</div>

</div>

我履行了这一职责,但坠毁了任何浏览器。

function opacity_test(index)
{
    $( .block-item ).eq( index ).animate({
        opacity:0
    },500);

    setInterval( function() {
        opacity_test(index + 1);
    }, 1000 );
}

感谢。

最佳回答

为此:

var delay = 0;
$( .block-item:lt(16) ).each(function(){ 
               //^^ do for every instance less than the 16th (starting at 0)
    $(this).delay(delay).animate({
        opacity:0
    },500);
    delay += 500;
});

Fiddle: http://jsfiddle.net/maniator/VS8tQ/3/

问题回答

You can use the "completion callback" of .animate() to start the next fade:

function fade(index) {
    $( .block-item ).eq(index).animate({
        opacity: 0
    }, function() {
        // on completion, recursively call myself
        // against the next element
        if (index < 15) {
            fade(index + 1);
        }
    })
}

fade(0);

见http://jsfiddle.net/alnitak/3DuTG/“http://jsfiddle.net/alnitak/3DuTG/。

An option using the callback, and to stop when it reaches the 16th element you can use .index()

var f = function($current) {
    $current.animate({
        opacity: 0
    }, function() {
        if ($current.next(".block-item").index() < 15) {
            f($current.next(".block-item"));
        }
    });
};

f($(".block-item:first"));

Example on jsfiddle





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签