我正在尝试在我的网站的移动版本中为“div”设置动画。
$(function(){
$( "#iconReorder" ).bind( "tap", tapHandler );
function tapHandler( event ){
$( "#iconReorder" ).animate({
marginLeft: "15px"
}, 500 );
}
});
当“div”将改变位置时,我希望能够再次点击它并让它返回到默认位置。
我试图创建一个“if”语句......但我不明白为什么它不起作用。我想假设我的 'div' 的 'marginLeft' 作为我的 javascript 代码的变量,以便在 'marginLeft=10px' 时将其移动到右侧,如果“new”则将其移动到左侧(默认位置) 'marginLeft 不再等于 10px。我尝试过使用以下代码:
var x = ("#iconReorder").style.marginLeft;
if (x = "10px") {
$(function(){
$( "#iconReorder" ).bind( "tap", tapHandler );
function tapHandler( event ){
$( "#iconReorder" ).animate({
marginLeft: "15px"
}, 500 );
}
});
} else {
$(function(){
$( "#iconReorder" ).bind( "tap", tapHandler );
function tapHandler( event ){
$( "#iconReorder" ).animate({
marginLeft: "10px"
}, 1000 );
}
});
}
有人可以帮助我吗?我希望我所说的可以理解。谢谢