[英]How to add padding-left in javascript?
How do I change the padding-left
for an element in JavaScript? 如何在JavaScript中更改元素的
padding-left
? I have used this code and it works: 我使用了这段代码,它的工作原理如下:
$(".number_1").stop().animate({height: '295px', width: '210px', opacity: 1}, 100);
However, when I add padding-left
to the code, it doesn't work: 但是,当我向代码添加
padding-left
,它不起作用:
$(".number_1").stop().animate({padding-left: '10px', height: '295px', width: '210px', opacity: 1}, 100);
How do I add padding-left
in code for it to work? 如何在代码中添加
padding-left
以使其工作?
String in key for objects without quotes only work when they can be parsed successfully. 没有引号的对象的键中的字符串仅在可以成功解析时才起作用。 Add quotes around padding left and that should work.
在填充左边添加引号,这应该有效。
$(".number_1").stop().animate({"padding-left": '10px' ,height: '295px' ,width: '210px' ,opacity: 1}, 100);
add quote (")
if using padding-left
or change first latter into upper case if properly have -
then use paddingLeft
添加引号
(")
如果使用padding-left
或将第一个后者更改为大写,如果正确使用-
则使用paddingLeft
$(".number_1").stop().animate({paddingLeft: '10px' ,height: '295px' ,width: '210px' ,opacity: 1}, 100);
OR 要么
$(".number_1").stop().animate({"padding-left": '10px' ,height: '295px' ,width: '210px' ,opacity: 1}, 100);
You have to wrap the style rule in quotes: 您必须将样式规则包装在引号中:
.animate({'padding-left' : '20px' });
Or you can use this: 或者您可以使用此:
$("#p1").animate({paddingLeft:"+=100px"});
Here is a W3Schools Tryit Editor demonstrating how to use 'padding-left' or 'paddingLeft' in JQuery animations. 这是一个W3Schools Tryit编辑器,演示如何在JQuery动画中使用'padding-left'或'paddingLeft'。
尝试'paddingLeft'而不是'padding-left'。
Use paddingLeft
when you're working with javascript, although in this specific case 'padding-left'
might also work (not entirely sure on that though, as that would be a jQuery specific implementation thing). 当你使用javascript时使用
paddingLeft
,虽然在这个特定情况下'padding-left'
也可能有用(虽然不完全确定,因为那将是一个特定于jQuery的实现)。
$(".number_1").stop().animate({paddingLeft: '10px' ,height: '295px' ,width: '210px' ,opacity: 1}, 100);
And just a general tip, you should not put a space before the comma, but after it. 只是一般性的提示,你不应该在逗号之前放置一个空格,而是在它之后。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.