jquery CSS 在 webkit 中不起作用

标签 jquery css webkit

如果图像是纵向的,我正在尝试将一些 css 应用于图像标签,但由于某些原因,.css() 在 webkit 中不起作用。基本上图像标签没有获得“样式”属性。这是我的代码:

$(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>

我试过使用 .attr() 而不是 .css() 但没有用。这是行不通的!

知道为什么吗?

最佳答案

.ready() 被触发时,图像可能没有设置尺寸。

0 > 0 为假,因此永远不会设置 top 属性。

使用$(window).load();相反,或者 this plugin .

关于jquery CSS 在 webkit 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7888546/

相关文章:

javascript - 单击按钮文本并释放它(但仍在按钮内)时,按钮元素未触发单击事件?

css - 为什么 webkit 浏览器的转换持续时间总是固定的?

javascript - 如何在 WordPress 页面加载时加载 woocommerce get_session_cookie?

javascript - jQuery 卸载在 Chrome 中不起作用

javascript - 在同一页面上 Bootstrap 多个选项卡并仅显示一个选项卡

Javascript\jQuery : is it possible to overlay elements using x and y coordinates?

html - 为什么只有一些 CSS 边距会塌陷?

javascript - 创建 Wordpress 网站的移动版本

linux - 在 GTK 中注入(inject)鼠标事件 (WebKitWebView)

jquery - 如何使用 jQuery 编辑评论?