移动背景,而mousemove

时间:2014-08-13 17:07:31

标签: javascript jquery html css mousemove

我有一个问题,当我重新加载我的页面时,页面从左侧开始,但我需要在中心。我该怎么办? 接下来,当它位于中心时,它应向左滚动,直到它为20px,因此向右滚动。顶部和底部无关紧要。 2.JPG分辨率为2743宽度,768高度。

这是我的代码:

的CSS:

    * {
    margin-left:-90px;
    margin-top:-10px;
    padding:-60px;
}
body {
    background:white;
}
.bg {
    background:url("2.JPG");
    background-repeat:no-repeat;
    height:768px;
    width:2743px;
    display:block;
}

已连接^ jquery 1-7分钟js

的javascript

$(document).ready(function(){
$(this).bind('mousemove',function(e){
    $("#bg").css({ "margin-top":e.pageY/100, "margin-left":e.pageX/6 });
});
    setTimeout(function() {
    $('#top').cycle({
        delay:  -1500
    });
    $('.pics img').css({
        opacity: 0.5
    });
}, 0);
setTimeout(function(){
    $('#bottom').cycle({
        delay:  -3000
    });
    $('.pics img').css({
        opacity: 0.5
    });
}, 0);
});

这是我的HTML:

<div class="bg" id="bg">&nbsp;</div>

非常感谢,对不起我的英语和我的设计知识:)

1 个答案:

答案 0 :(得分:0)

您可以通过onmousemove javascript事件轻松完成

或者您可以尝试这个问题,我希望它能运作 http://css-tricks.com/auto-moving-parallax-background/

相关问题