[英]Rotate image when scrolling
after using stackoverflow for plenty of help in the past I have a problem which will probably be easy for someone to solve… 在过去使用stackoverflow寻求大量帮助后,我遇到了一个问题,该问题可能很容易解决。
I'm trying to rotate a background image when the user scrolls down the page, I have managed to get this far (with help from someone else's question and some helpful answers) but I need to slow down the rotation as its to fast. 当用户向下滚动页面时,我正在尝试旋转背景图像,我已经设法做到了这一点(在其他人的问题和一些有用的答案的帮助下),但是我需要将旋转速度减慢以使其快速。 As far as I can tell I need to do something with the window height and use this to slow the rotation. 据我所知,我需要对窗口高度进行一些操作,并使用它来减慢旋转速度。
Heres my JSFiddle of how far I've got. 这是我走了多远的JSFiddle 。
If anyone could help me out I'd be very grateful, my skills aren't quite up to scratch. 如果有人能帮助我,我将不胜感激,我的技能还不够。
My code… 我的代码...
$(function() {
var rotation = 0,
scrollLoc = $(document).scrollTop();
$(window).scroll(function() {
var newLoc = $(document).scrollTop();
var diff = scrollLoc - newLoc;
rotation += diff, scrollLoc = newLoc;
var rotationStr = "rotate(" + rotation + "deg)";
$(".circle").css({
"-webkit-transform": rotationStr,
"-moz-transform": rotationStr,
"transform": rotationStr
});
});
})
CSS: CSS:
.container {
width:960px;
margin: 0 auto;
}
.circleWrap {
margin: 0 auto;
width:960px;
position:relative;
}
.circleContainer {
width: 970px;
position:fixed;
overflow:visible;
z-index:-50;
}
.circle{
background:url('http://www.wearerevolting.co.uk/dev/spin/moodring-col.jpg') no-repeat center;
width: 1772px;
height: 1772px;
margin-left: -400px;
}
.text {
z-index:50;
position:absolute;
height:2000px;
width:960px;
border:#000 thick solid;
}
<div class="container">
<div class="text">Content area</div>
</div>
<div class="circleWrap">
<div class="circleContainer">
<div class="circle"></div>
</div>
</div>
Cheers! 干杯!
Change 更改
var rotationStr = "rotate(" + rotation + "deg)";
to 至
var rotationStr = "rotate(" + rotation / 100 + "deg)";
where 100
is an arbitrary limiting value. 其中100
是任意极限值。 Updated demo 更新的演示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.