[英]Jquery change background size
I have problem with changing background-size via jQuery. 我在通过jQuery更改背景大小时遇到问题。 It works when you give only one parameter, but when I give 2 parameter it doesn't work, I need to send via jQuery 2 variables into background-size for width and height.
当您仅给出一个参数时,它可以工作,但是当我给出2个参数时,它不起作用,我需要通过jQuery 2变量将其宽度和高度发送到background-size中。
here is my js code example. 这是我的js代码示例。
var w = 100;
var h = 100;
$("div").css("background-size", w+"px" + h + "px");
here is demo 这是演示
http://jsfiddle.net/Lv4wt75f/ http://jsfiddle.net/Lv4wt75f/
it's just a simple example in real version I need to send 2 parameter that calculate ratio. 这只是真实版本中的一个简单示例,我需要发送2个参数来计算比率。
Thanks 谢谢
Because both those parameters need to have a space in between. 因为这两个参数之间都必须有一个空格。 You simply need one extra space
您只需要一个额外的空间
$("div").css("background-size", w+"px " + h + "px");
^
您需要在该px之间留一个空格。
$("div").css("background-size", w+"px " + h + "px");
^ (Space Here)
$("div").css("background-size": w+"px " + h+"px");
^ (Space)
use :(colon) instead of ,(comma) after background-size 在背景大小之后使用:(冒号)代替,(逗号)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.