【问题标题】:My moving background won't stretch, but rather have a static place. I can't seem to change that我的移动背景不会拉伸,而是有一个静态的地方。我似乎无法改变这一点
【发布时间】:2019-04-06 05:35:29
【问题描述】:

所以我有一个用 javascript 制作的移动背景,现在我想拉伸我的背景。我使用并搜索了很多方法,但找不到任何解决方案。它不会向我显示文本(它在背景后面)并且图片保持静态。

我已经尝试过那些有背景的解决方案:例如封面。

这是我的背景图片的css代码。

#section1 { 
    height: 100%;
    width: 100%;
    position: absolute;
    background-attachment: fixed;
    background-image: url("../IMG/Background.png");
} 

也许这对手头的问题也很有用,但我已经有这个工作了。

var i=1;

function move(){
    i++;
    document.getElementById("section1").style.backgroundPosition=i+"px";
}

window.onload = function(){
    var move1 = setInterval(move, 30);
}

【问题讨论】:

    标签: javascript html css


    【解决方案1】:

    根据 mdn (https://developer.mozilla.org/en-US/docs/Web/CSS/background-position) 上的文档,您分配给 backgroundPosition 的值似乎无效。 它可能是(在其他格式中),像这样: background-position: 50px 100px;

    【讨论】:

      【解决方案2】:

      您必须将background-size: cover; 添加到样式中:

      #section1 {
        height: 100%;
        width: 100%;
        position: absolute;
        background-attachment: fixed;
        background-size: cover;
        background-image: url("../IMG/Background.png");
      }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-04-20
        • 2019-04-12
        • 1970-01-01
        • 1970-01-01
        • 2011-02-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多