我希望我的 div 向左移动 5 次,然后再返回。 为此,我有那个脚本:
Java脚本:
$(document).ready(function() {
if(document.getElementById('twitter').style.marginLeft == "-278%")
{
(function($){
setInterval(function(){
$('#twitter').animate({
marginLeft: '+=278%',
},3000);
}, 5000);
})(jQuery);
}else{
(function($){
setInterval(function(){
$('#twitter').animate({
marginLeft: '-=55.6%',
},2000);
}, 5000);
})(jQuery);
}
});
我有一个使用 px 的工作脚本:
if($('#twitter').css("marginLeft")==('-5300px'))
但我需要百分比来响应,有人可以帮我吗?
编辑:
动画正在运行,只是 if 的条件不起作用。
最佳答案
使用position: absolute
和left
属性代替margin-left
<div id='twitter'>
hello
</div>
#twitter{
position: absolute;
left: -50%;
}
关于javascript - 如果 margin left == 百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40151707/