admin管理员组文章数量:1022769
I'm certain I've seen this before. This is how i remember it
$cnta.css({ top:'+=50' });
Needless to say, it doesn't work :-)
I know i can parse the css value, manipulate the result and put it back into css, but that takes twice the code.
Thanks for answers!
I'm certain I've seen this before. This is how i remember it
$cnta.css({ top:'+=50' });
Needless to say, it doesn't work :-)
I know i can parse the css value, manipulate the result and put it back into css, but that takes twice the code.
Thanks for answers!
Share Improve this question asked Jul 31, 2010 at 21:36 HubroHubro 59.5k73 gold badges237 silver badges402 bronze badges1 Answer
Reset to default 8That works for .animate()
:
$cnta.animate({ top:'+=50' }, 0);
For .css()
, you can pass a function that will do the addition for you:
$cnta.css('top', function(i,current) { return parseInt(current) + 50; });
$cnta.css('top', function(i,current) { return (parseInt(current) + 50 || 50); });
EDIT: Changed the animation from 1
to 0
. As @Nick Craver noted, a 0
animation will work.
EDIT: Gave a better answer for the .css()
version. If the top
has not been given any value yet, then doing .parseInt(current)
will return NaN
. Updated to correct it.
I'm certain I've seen this before. This is how i remember it
$cnta.css({ top:'+=50' });
Needless to say, it doesn't work :-)
I know i can parse the css value, manipulate the result and put it back into css, but that takes twice the code.
Thanks for answers!
I'm certain I've seen this before. This is how i remember it
$cnta.css({ top:'+=50' });
Needless to say, it doesn't work :-)
I know i can parse the css value, manipulate the result and put it back into css, but that takes twice the code.
Thanks for answers!
Share Improve this question asked Jul 31, 2010 at 21:36 HubroHubro 59.5k73 gold badges237 silver badges402 bronze badges1 Answer
Reset to default 8That works for .animate()
:
$cnta.animate({ top:'+=50' }, 0);
For .css()
, you can pass a function that will do the addition for you:
$cnta.css('top', function(i,current) { return parseInt(current) + 50; });
$cnta.css('top', function(i,current) { return (parseInt(current) + 50 || 50); });
EDIT: Changed the animation from 1
to 0
. As @Nick Craver noted, a 0
animation will work.
EDIT: Gave a better answer for the .css()
version. If the top
has not been given any value yet, then doing .parseInt(current)
will return NaN
. Updated to correct it.
版权声明:本文标题:javascript - What's jQuery's css syntax for addition and subtraction on numerical values? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745528598a2154644.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论