[英]Removing a specific element from a class
I have this code, it moves every element in the class "block" 10 pixels to the left. 我有这段代码,它将“块”类中的每个元素向左移动10个像素。 I want it to remove any of the elements which are left of 300 pixels.
我希望它删除任何剩余300像素的元素。 Why does
$(this).remove()
not work and what can I do to fix this? 为什么
$(this).remove()
不起作用,我该怎么解决?
$(".block").animate({left:"-=10"},speed,"linear",function(){
if(parseInt(this.style.left) < 300)
{
$(this).remove();
//something
}else{
//something
}
});
html: HTML:
<div id="container">
<span class="block"></span>
<span class="block"></span>
</div>
Here's all of my code http://jsbin.com/ExET/1/ 这是我所有的代码http://jsbin.com/ExET/1/
Like this? 像这样? jsFiddle
的jsfiddle
$('div').on('mouseover', function() {
$(this).animate({
left: '+=10'
}, 200, 'linear', function() {
if($(this).offset().left > 50) {
$(this).remove();
} else {
$(this).css('background', 'blue');
}
});
});
You will need to change the values but it achieves the effect you desire. 您将需要更改值,但可以实现所需的效果。
This is what you want: http://jsbin.com/olipOh/4/watch?html,css,js,output 这就是您想要的: http : //jsbin.com/olipOh/4/watch?html,css,js,output
You need to select child elements: 您需要选择子元素:
$(".block").find("*")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.