滚动时旋转图像
Rotate image when scrolling
在过去使用stackoverflow获得大量帮助后,我遇到了一个问题,可能很容易解决…
当用户向下滚动页面时,我试图旋转背景图像,我已经做到了这一点(在别人的问题和一些有用的答案的帮助下),但我需要放慢旋转速度,因为它太快了。据我所知,我需要对窗户的高度做点什么,并用它来减缓旋转。
这是我的JSFiddle关于我已经走了多远。
如果有人能帮我,我将不胜感激,因为我的技术还不完全达到标准。
我的代码…
$(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:
.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>
干杯!
更改
var rotationStr = "rotate(" + rotation + "deg)";
至
var rotationStr = "rotate(" + rotation / 100 + "deg)";
其中CCD_ 1是任意的极限值更新的演示
相关文章:
- 需要关于随机图像旋转的指南
- Jquery CSS背景图像旋转
- 全屏背景图像+旋转图像
- 随机图像旋转的多个实例
- JS下拉菜单显示在图像旋转器上
- 请解释Javascript图像旋转代码
- JavaScript 中的图像旋转器(键下)
- jquery 图像旋转器(仅在 JS 中传递图像)
- 如何停止多次单击下一个以破坏我的图像旋转器
- 停止 3 个图像旋转只需单击一个按钮
- 背景图像旋转器.php + jQuery每4秒显示一次随机照片
- 图像旋转背景 js 跳转到页面顶部
- 画布图像旋转中的问题
- 在画布上绘制多个图像,每个图像旋转
- 使用关键帧图像旋转器时,图像不会在两个块之间同步协调
- 最简单的图像旋转器 - 使用设置间隔失败
- 需要按钮显示/隐藏图像旋转 href 添加到 javascript 代码中
- 图像旋转和Jcrop.js
- 360 度图像旋转指示器
- 通过手机加载时,画布图像会将图像旋转 90 度