簡體   English   中英

-webkit-background-size 不適用於 jQuery Css

[英]-webkit-background-size doesn't work with jQuery Css

我試圖在頁面加載后加載背景,但它似乎不像我預期的那樣工作。

我之前在 css 中的代碼是:

html {
    background: url(<?php echo $this->Cdn->getUrl(); ?>/images/photos/bg-blurred.jpg) no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    background-color: #0c1d31;
}

現在我用 jQuery 試試:

jQuery(document).ready(function () {

    jQuery('html').css({
        'background-image': "url('<?php echo $this->Cdn->getUrl(); ?>/images/photos/bg-blurred.jpg')",
        'background-size': "cover",
        'background-color': "#0c1d31",
        '-webkit-background-size': "cover",
        '-moz-background-size': "cover",
        '-o-background-size': "cover",

    }); 
});

似乎“-webkit-background-size”和“-moz-background-size”和“-o-background-size”在使用 jQuery.css 時不起作用。 其他 css 屬性工作正常。

請問有什么想法嗎?

如果您僅嘗試使用“-webkit-background-size”:

jQuery(document).ready(function () {

   jQuery('html').css({
      '-webkit-background-size': "cover"
   });
});

你會看到你的元素看起來像這樣:

<html style="background-size: cover;">

所以這不是你的問題。

您可能應該查找您的網址:

"url('<?php echo $this->Cdn->getUrl(); ?>/images/photos/bg-blurred.jpg')"

如果您使用的是 chrome,請檢查網絡選項卡內的 f12,以查看是否有錯誤。

對不起,這是我的錯誤。 我想念我的 JS 中的一些代碼...

    jQuery('html').css({
        'background-image': "url('<?php echo $this->Cdn->getUrl(); ?>/images/photos/bg-blurred.jpg')",
        "background-repeat": "no-repeat",
        "background-position": "center center",
        "background-attachment": "fixed",
        'background-size': "cover",
        'background-color': "#0c1d31",
        '-webkit-background-size': "cover",
        '-moz-background-size': "cover",
        '-o-background-size': "cover",
    });

很好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM