简体   繁体   English

圆形视差背景定位

[英]Circular parallax background positioning

I'm using a script to move the background position a certain pixel distance based on mouse movement/phone movement. 我正在使用脚本根据鼠标移动/电话移动将背景位置移动一定的像素距离。 However, I'm having trouble coming up with a way to always have the background extending the entire width and height of the containing div. 但是,我很难提出一种始终使背景扩展包含div的整个宽度和高度的方法。 The script does work to move the background based on the mouse movement.. but it's moving the background image too much and it's causing white space. 该脚本确实可以根据鼠标的移动来移动背景。.但是它移动的背景图像过多,从而导致空白。

Take a look at the fiddle and you'll see what I mean. 看看小提琴,您会明白我的意思。

FIDDLE: http://jsfiddle.net/K9Ae7/2/ 内容: http : //jsfiddle.net/K9Ae7/2/

HTML: HTML:

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

CSS: 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: JS:

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

        });
    },

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

The rest of the script is in the fiddle. 脚本的其余部分在小提琴中。 Thanks. 谢谢。

Check this out: 看一下这个:

#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 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM