gpt4 book ai didi

javascript - 鼠标移动时移动背景

转载 作者:行者123 更新时间:2023-11-28 09:44:56 24 4
gpt4 key购买 nike

我有一个问题,当我重新加载我的页面时,页面从左边开始,但我需要这个在中间。我应该怎么做?接下来,当它位于中心时,它应该向左滚动直到 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>

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

最佳答案

你可以通过javascript的onmousemove事件轻松做到这一点

或者你可以试试这个来解决你的问题,我希望它能奏效 http://css-tricks.com/auto-moving-parallax-background/

关于javascript - 鼠标移动时移动背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25292157/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com