仿京东专题的图追踪鼠标动的效果
2018-01-24 19:58
183 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>onMouseMove</title>
<script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
</head>
<style>
.movebox{background:#00ddff;width:1000px;height:600px;position: relative;}
.bird{background:url(http://www.qqw21.com/article/UploadPic/2012-8/2012812234952102.jpg) no-repeat center center;position:absolute;left: 254px; top: 100px;z-index:2; width: 200px; height:200px; }
.hua{background: url(http://www.zuo3.com/images/v/r/img02/r/t/101/bao/uploaded/i2/T1UTxhXox8dJPv9vMT_011613.jpg_310x310.jpg) no-repeat center center;position: absolute;right:200px;bottom:100px;width:200px;height:200px;}
</style>
<body>
<div class="movebox">
<div class="mousemove-item bird" data-z="1"></div>
<!--必须引入类名mousemove-item 设置属性data-z-->
<div class="mousemove-item hua" data-z="2"></div>
</div>
<script>
$(function(){
// 鼠标晃动 效果
$(function(){
function getTransforms(translate3d) {
return {
'-webkit-transform': translate3d,
'-moz-transform': translate3d,
'-ms-transform': translate3d,
'transform': translate3d
};
}
function transformContainer(element, translate3d) {
element.css(getTransforms(translate3d));
}
var noAnimate = !1;
var winWidth = $(window).width(),winHeight = $(window).height();
function onMouseMove(ev) {
if (!noAnimate) {
var left = (ev.clientX - .6 * winWidth) / (.6 * winWidth),
top = (ev.clientY - .6 * winHeight) / (.6 * winWidth),
elements = $(".mousemove-item");
elements.each(function() {
var el = $(this),
pos = {
left: this.style.left,
top: this.style.top
},
rate = parseInt(el.data("z")),
max = 4 * (8 - rate),
toLeft = pos.left + left * max,
toTop = pos.top + top * max;
transformContainer(el, "translate(" + toLeft + "px, " + toTop + "px)" );
})
}
}
$('.movebox').on('mousemove',onMouseMove);
})
})
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>onMouseMove</title>
<script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
</head>
<style>
.movebox{background:#00ddff;width:1000px;height:600px;position: relative;}
.bird{background:url(http://www.qqw21.com/article/UploadPic/2012-8/2012812234952102.jpg) no-repeat center center;position:absolute;left: 254px; top: 100px;z-index:2; width: 200px; height:200px; }
.hua{background: url(http://www.zuo3.com/images/v/r/img02/r/t/101/bao/uploaded/i2/T1UTxhXox8dJPv9vMT_011613.jpg_310x310.jpg) no-repeat center center;position: absolute;right:200px;bottom:100px;width:200px;height:200px;}
</style>
<body>
<div class="movebox">
<div class="mousemove-item bird" data-z="1"></div>
<!--必须引入类名mousemove-item 设置属性data-z-->
<div class="mousemove-item hua" data-z="2"></div>
</div>
<script>
$(function(){
// 鼠标晃动 效果
$(function(){
function getTransforms(translate3d) {
return {
'-webkit-transform': translate3d,
'-moz-transform': translate3d,
'-ms-transform': translate3d,
'transform': translate3d
};
}
function transformContainer(element, translate3d) {
element.css(getTransforms(translate3d));
}
var noAnimate = !1;
var winWidth = $(window).width(),winHeight = $(window).height();
function onMouseMove(ev) {
if (!noAnimate) {
var left = (ev.clientX - .6 * winWidth) / (.6 * winWidth),
top = (ev.clientY - .6 * winHeight) / (.6 * winWidth),
elements = $(".mousemove-item");
elements.each(function() {
var el = $(this),
pos = {
left: this.style.left,
top: this.style.top
},
rate = parseInt(el.data("z")),
max = 4 * (8 - rate),
toLeft = pos.left + left * max,
toTop = pos.top + top * max;
transformContainer(el, "translate(" + toLeft + "px, " + toTop + "px)" );
})
}
}
$('.movebox').on('mousemove',onMouseMove);
})
})
</script>
</body>
</html>
相关文章推荐
- web前端javaScript仿京东淘宝图片鼠标浮动图片上移效果
- 仿京东(我的商城)鼠标上去弹出层效果
- 3D建模和3D渲染技术专题一: 热身篇,光线追踪(path Tracing),环境光阴影(ambient occlusion),焦距效果(effect focus)介绍
- jquery图片放大效果,鼠标经过图片时局部放大,类似京东图片放大镜效果
- 京东首页很炫的js效果、图片自动滑动,悬停效果,鼠标离开效果
- 仿照京东做的一个鼠标移上去的图片文字说明效果
- web前端javaScript仿京东淘宝图片鼠标浮动图片上移效果
- web前端javaScript仿京东淘宝图片鼠标浮动图片上移效果
- web前端javaScript仿京东淘宝图片鼠标浮动图片上移效果
- 基于jquery实现的鼠标拖拽元素复制并写入效果
- JS实现“鼠标控制局部文字滚动效果”研究
- DOM设置表格隔行变色js代码及鼠标悬停在哪行,哪行字体就加粗效果
- JavaScript模拟鼠标右键菜单效果
- 动画效果鼠标点击打开/关闭层
- 基于JQuery的一个简单的鼠标跟随提示效果
- CSS+jQuery实现的鼠标滑过图片周围图片变暗的效果
- js 鼠标拖动对象 可让任何div实现拖动效果
- jq实现鼠标点击效果 当前位置
- jquery实现鼠标拖动图片效果示例代码