jQuery animate({left:& ++ 10& quot;})不起作用 [英] jQuery animate({left:"+=10"}) not working

查看:138
本文介绍了jQuery animate({left:& ++ 10& quot;})不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<script type="text/javascript" src="./Scripts/jquery-1.5.1.min.js"></script>
<script type='text/javascript' >
    $(document).ready(function () {
        $("#start").animate({ left: "+=10px" }, 1000)
            .animate({ left: "-5000px" }, 1000);
    });
</script>

<p id="start">this is some text that i am going to animate </p>

关于这为什么没有动画,我正在绞尽脑汁.如果将left更改为marginLeft,它将按预期工作并进行动画处理.但是我不确定为什么left没有.

I am racking my brain here as to why this doesn't animate. If I change left to marginLeft it will work as expected and animates. But i am not sure why left doesn't.

有人可以解释吗?我看过许多其他脚本也做了类似的事情.

Can anyone explain please? I have seen many other scripts doing something similar.

推荐答案

要进行定位工作,您需要通过设置position css属性来启用它.

For positioning to work, you need to have enabled it by setting the position css property.

将其设置为fixedabsoluterelative即可正常工作(取决于您要实现的目标)

Set it to fixed or absolute or relative to work (depending on what you try to achieve)

引用 position MDC文档 属性.

Quoting from the specs of the position MDC docs property.

初始值:静态

静态
正常行为. top right bottom left 属性不 申请.

static
Normal behavior. The top, right, bottom, and left properties do not apply.

这篇关于jQuery animate({left:&amp; ++ 10&amp; quot;})不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆