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.
Using jQuery css() method it keeps setting it to 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?
像这样设置它
$(this).css("flex", value);
Add px
after value
variable
$('.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.
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.