簡體   English   中英

從類中刪除特定元素

[英]Removing a specific element from a class

我有這段代碼,它將“塊”類中的每個元素向左移動10個像素。 我希望它刪除任何剩余300像素的元素。 為什么$(this).remove()不起作用,我該怎么解決?

    $(".block").animate({left:"-=10"},speed,"linear",function(){

        if(parseInt(this.style.left) < 300)
        {
            $(this).remove();
            //something
        }else{
            //something
        }
    });

HTML:

    <div id="container">
       <span class="block"></span>
       <span class="block"></span>
    </div>

這是我所有的代碼http://jsbin.com/ExET/1/

像這樣? 的jsfiddle

$('div').on('mouseover', function() {
    $(this).animate({ 
        left: '+=10' 
    }, 200, 'linear', function() {
        if($(this).offset().left > 50) {
            $(this).remove();
        } else {
            $(this).css('background', 'blue');
        }   
    });
});

您將需要更改值,但可以實現所需的效果。

這就是您想要的: http : //jsbin.com/olipOh/4/watch?html,css,js,output

您需要選擇子元素:

$(".block").find("*")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM