admin管理员组文章数量:1291595
I have problem with changing background-size via 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.
here is my js code example.
var w = 100;
var h = 100;
$("div").css("background-size", w+"px" + h + "px");
here is demo
/
it's just a simple example in real version I need to send 2 parameter that calculate ratio.
Thanks
I have problem with changing background-size via 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.
here is my js code example.
var w = 100;
var h = 100;
$("div").css("background-size", w+"px" + h + "px");
here is demo
http://jsfiddle/Lv4wt75f/
it's just a simple example in real version I need to send 2 parameter that calculate ratio.
Thanks
Share Improve this question asked Feb 23, 2015 at 6:30 Aram MkrtchyanAram Mkrtchyan 2,7004 gold badges35 silver badges48 bronze badges 1- w3schools./cssref/… – Sadikhasan Commented Feb 23, 2015 at 6:38
4 Answers
Reset to default 4Because both those parameters need to have a space in between. You simply need one extra space
$("div").css("background-size", w+"px " + h + "px");
^
Fiddle
Syntax Reference
You need a space between that px.
$("div").css("background-size", w+"px " + h + "px");
^ (Space Here)
$("div").css("background-size": w+"px " + h+"px");
^ (Space)
use :(colon) instead of ,(ma) after background-size
本文标签: javascriptJquery change background sizeStack Overflow
版权声明:本文标题:javascript - Jquery change background size - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741535366a2383994.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论