【问题标题】:Circular parallax background positioning圆形视差背景定位
【发布时间】:2025-12-07 08:10:02
【问题描述】:

我正在使用脚本根据鼠标移动/手机移动将背景位置移动一定像素距离。但是,我很难想出一种方法来始终让背景扩展包含 div 的整个宽度和高度。该脚本确实可以根据鼠标移动来移动背景。但是它移动了太多的背景图像并导致了空白。

看看小提琴,你就会明白我的意思了。

小提琴:http://jsfiddle.net/K9Ae7/2/

HTML:

<section id="court-fitness" data-parallaxify-background-range="30"></section>

CSS:

#court-fitness {
height: 500px;
width: 100%;
background:url('https://www.tourresource.com/Board/Themes/SMF_Grunge/images/bg.jpg');
background-repeat: no-repeat;
}

JS:

        $('#court-fitness').hover(function () {
        $(this).parallaxify({
            parallaxBackgrounds: true,
            useMouseMove: true,
            useGyroscope: true,
            inputPriority: 'mouse'

        });
    },

    function () {
        $(this).parallaxify('destroy');
    });

脚本的其余部分在小提琴中。谢谢。

【问题讨论】:

  • 您可以将页面背景设置为黑色,以便看不到空白区域。

标签: javascript jquery html css


【解决方案1】:

看看这个:

#court-fitness {
    height: 500px;
    width: 110%;
    margin-left: -5%;
    margin-top: -5%;
    background:url('https://www.tourresource.com/Board/Themes/SMF_Grunge/images/bg.jpg');
    background-repeat: no-repeat;
    background-size: cover;
    overflow: hidden;
    z-index: -1;
}

Fiddle

【讨论】:

  • 这绝对适用于宽度!我还在努力调整身高。我为高度应用了相同的代码,它与我的一些元素重叠。