jquery CSS doesn't work in webkit
Posted
by
Mauro74
on Stack Overflow
See other posts from Stack Overflow
or by Mauro74
Published on 2011-10-25T11:27:35Z
Indexed on
2012/10/27
23:01 UTC
Read the original article
Hit count: 252
I'm trying to apply some css to an image tag if the image is portrait, but for some reason .css() doesn't work in webkit. Basically the image tag doesn't get the 'style' property. Here's my code:
$(document).ready(function () {
$('.listing .item .thumb img').each(function () {
var _img = $(this);
var _imgWidth = _img.outerWidth();
var _imgHeight = _img.outerHeight();
if (_imgHeight > _imgWidth) {
_img.css('top', '-40%');
}
});
});
<div class="listing about">
<div class="item">
<a href="#" class="thumb">
<img src="../_uploads/siteassets/images/thumb-carousel-2.jpg" />
<span class="frame"></span>
</a>
<span class="snippet">
<a href="#" class="title">Name Surname</a>
<span class="date">Role in the company</span>
<p class="description">Lorem ipsum dolor sit amet...</p>
</span>
</div>
</div>
I've tried to use .attr() instead of .css() but nothing. It doesn't work!
Any idea why?
© Stack Overflow or respective owner