jQuery:如何表示 div 的宽度 +多几个像素?

发布于 2025-01-05 10:34:54 字数 232 浏览 3 评论 0原文

我想将 div 动画设置到左侧,即 div 的宽度 + 100px。

我有这样的代码:

$('#mydiv').animate({left:-$('#mydiv').outerWidth()},1000);

这会在 1000 毫秒内向左移动到 #mydiv 宽度的距离。

我怎样才能再添加 100 个像素呢?

将不胜感激您的专业建议!

I want to animate a div to the left, to the width of the div + 100px.

I have this code:

$('#mydiv').animate({left:-$('#mydiv').outerWidth()},1000);

This animates it in 1000 milliseconds to the left, to the distance of the width of #mydiv.

How can I add 100 more pixels to that?

Would be grateful for your expertly advice!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

两人的回忆 2025-01-12 10:34:54

为什么不试试这个呢:

$('#mydiv').animate({left:-($('#mydiv').width() + 100)},1000);

Why not try this instead:

$('#mydiv').animate({left:-($('#mydiv').width() + 100)},1000);
So要识趣 2025-01-12 10:34:54

$('#mydiv').animate({left:-($('#mydiv').outerWidth() + 100)},1000);

$('#mydiv').animate({left:-($('#mydiv').outerWidth() + 100)},1000);

黑白记忆 2025-01-12 10:34:54

尝试:

var width = $('#mydiv').outerWidth();
$('#mydiv').animate({
    left: (width + 100)
},1000);

不确定为什么在左值之前需要减法运算符?

Try:

var width = $('#mydiv').outerWidth();
$('#mydiv').animate({
    left: (width + 100)
},1000);

Not sure why you need the subtraction operator before the left value?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文