0

我有这段代码,它将“块”类中的每个元素向左移动 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/

4

2 回答 2

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');
        }   
    });
});

您将需要更改这些值,但它会达到您想要的效果。

于 2013-08-22T02:17:06.897 回答
0

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

您需要选择子元素:

$(".block").find("*")
于 2013-08-22T02:36:10.443 回答