【问题标题】:Add css class before image load在图像加载之前添加 css 类
【发布时间】:2014-02-21 16:16:37
【问题描述】:

我有带有背景图片的容器。

如何在背景图片加载之前将 css 类添加到这个容器中?

现在我在 document.ready 上使用 JQuery 添加类 (New) 以重载另一个类 (Base) 的 css 规则。 在 Load 时,图像首先以 Base 类的 css 出现,然后根据 New 类显示。 问题:我可以看到图像何时在屏幕上拉伸。

        $(document).ready(function() {
           $('.content-wrap').addClass('home-view');
        }

【问题讨论】:

    标签: javascript jquery image load


    【解决方案1】:

    试试这个解决方案

    $('<img/>').attr('src', 'http://www.yoursite.com/yourpicture.png').load(function() {
      $(this).remove();
      $('.content-wrap').css('background-image', 'url(http://www.yoursite.com/yourpicture.png)');
    });
    

    问候。

    【讨论】:

    • 感谢您的回复。 .content-wrap - 不是具有背景图像的容器。但在 .content-wrap.home-view 的上下文中,我有我想要的 css 规则。
    猜你喜欢
    • 1970-01-01
    • 2013-03-09
    • 2012-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多