[英]Setting flex css with jQuery
I"m trying to set the flex css property of image containers to the aspect ratio of the image. I want the flex css to be in form flex: 1.798245
with no px or 1 1 1px. 我试图将图像容器的flex css属性设置为图像的宽高比。我希望flex css处于flex: 1.798245
形式flex: 1.798245
,没有px或1 1 1px。
Using jQuery css() method it keeps setting it to flex: 1 1 1.798245px
使用jQuery css()方法,它将其设置为flex: 1 1 1.798245px
//gallery flex
$('.gallery-item').each(function(){
var value = $("img", this).width() / $("img", this).height();
$(this).css("flex", value);
});
How should I pass value to css() to get the result I want? 我应该如何将值传递给css()以获得我想要的结果?
像这样设置它
$(this).css("flex", value);
Add px
after value
variable 在value
变量后添加px
$('.gallery-item').each(function(){
var value = $("img", this).width() / $("img", this).height();
$(this).css("flex", value); // You had used `:` but should be `,` to separate two arguments.
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.