Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将保存在变量中的像素量添加到jQuery中的css属性_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 将保存在变量中的像素量添加到jQuery中的css属性

Javascript 将保存在变量中的像素量添加到jQuery中的css属性,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我想将存储在变量“x”中的像素量添加到jQuery中的css属性中 我知道,由于jQuery 1.6,您可以很容易地使用如下内容: $(this).css({top: "+=150"}); 但当我使用一个变量而不是150时,它就不起作用了,因为变量必须用引号写出来 $(this).css({top: "+= x"}); 请试试这个 $(this).css({top: "+= "+ x +"px"}); 这将代替您的代码:$(This.css({top:“+=”+x})。如果您使用的是ES

我想将存储在变量“x”中的像素量添加到jQuery中的css属性中

我知道,由于jQuery 1.6,您可以很容易地使用如下内容:

$(this).css({top: "+=150"});
但当我使用一个变量而不是150时,它就不起作用了,因为变量必须用引号写出来

$(this).css({top: "+= x"});
请试试这个

$(this).css({top: "+= "+ x +"px"}); 
这将代替您的代码:
$(This.css({top:“+=”+x})。如果您使用的是ES6,请使用:
$(this.css({top:`+={x}})