jQuery背景图片跟随鼠标摆动js代码

版权:原创 更新时间:1年以上
[该文章底部包含文件资源,可根据自己情况,决定是否下载资源使用,时间>金钱,如有需要,立即查看资源]

以下是 jQuery背景图片跟随鼠标摆动js代码 的示例演示效果:

当前平台(PC电脑)
  • 平台:

部分效果截图:

jQuery背景图片跟随鼠标摆动js代码

HTML代码(index.html):

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>鼠标移上去图片摆动</title>
<meta charset="utf-8" />
<script src="js/jquery-1.9.1.min.js"></script>
<style type="text/css">
	.warp .top{position: absolute;width: 1920px;left: 50%;margin-left: -960px;height: 582px;overflow: hidden;}
	.box{position: relative;width: 1000px;height: 582px;overflow: hidden;margin:0 auto;background:#ff6a00;}
	.pic1{width: 1000px;height: 300px;position: absolute;left: 0;top: 282px;z-index: 114;}
	.pic2{width: 1022px;height: 473px;position: absolute;right: 439px;top: 109px;z-index: 113;}
	.pic3{width: 928px;height: 582px;position: absolute;left: 380px;top: 0;z-index: 112;}
	img{vertical-align: top;}
	.pic4{width: 1000px;height: 300px;position: absolute;left: 0;top: 282px;z-index: 113;}
	.pic5{width: 1000px;height: 300px;position: absolute;left: 0;top: 282px;z-index: 999;}
	.main{width: 1000px;margin: 0 auto;position: relative;}
</style>
</head>
<body>
<div class="top">
	<div class="pic2" >
		<img src="images/02.png">
	</div>
	<div class="pic3">
		<img src="images/03a.png">
	</div>
</div>
<div class="main">
	<div class="box">
		<div class="pic1">
			<img src="images/01_BG.png">
		</div>

		<div class="pic4">
			<img src="images/04.png">
		</div>
		<div class="pic5">
			<img src="images/05.png">
		</div>
	</div>
</div>
<script type="text/javascript">
$(function(){
    var positionX = 0;
    var positionY = 0;

    $('.pic5').mousemove(function(e) {
        var x = e.clientX, y = e.clientY;
        if(positionX === 0 && positionY === 0){
            positionX = x;
            positionY = y;
        }
        if(x > positionX && y < positionY){
            $('.pic1').stop().animate({'left':10,'top':292},'800',"easeOutCubic");
            $('.pic2').stop().animate({'right':449,'top':114},'800',"easeOutCubic");
            $('.pic3').stop().animate({'left':375,'top':5},'800',"easeOutCubic");
            $('.pic4').stop().animate({'left':-20,'top':300},'800',"easeOutCubic");
            positionX = x;
            positionY = y;
        }else if(x > positionX && y > positionY){
            $('.pic1').stop().animate({'left':-10,'top':280},'800',"easeOutCubic");
            $('.pic2').stop().animate({'right':429,'top':104},'800',"easeOutCubic");
            $('.pic3').stop().animate({'left':375,'top':-5},'800',"easeOutCubic");
            $('.pic4').stop().animate({'left':-20,'top':278},'800',"easeOutCubic");
            positionX = x;
            positionY = y;
        }else if(x < positionX && y < positionY){
            $('.pic1').stop().animate({'left':10,'top':292},'800',"easeOutCubic");
            $('.pic2').stop().animate({'right':449,'top':114},'800',"easeOutCubic");
            $('.pic3').stop().animate({'left':385,'top':5},'800',"easeOutCubic");
            $('.pic4').stop().animate({'left':20,'top':300},'800',"easeOutCubic");
            positionX = x;
            positionY = y;
        }else if(x < positionX && y > positionY){
            $('.pic1').stop().animate({'left':-10,'top':280},'800',"easeOutCubic");
            $('.pic2').stop().animate({'right':429,'top':104},'800',"easeOutCubic");
            $('.pic3').stop().animate({'left':385,'top':-5},'800',"easeOutCubic");
            $('.pic4').stop().animate({'left':20,'top':278},'800',"easeOutCubic");
            positionX = x;
            positionY = y;
        }
    })
    $.extend($.easing,{
        easeOutBack:function(x,t,b,c,d,s){
            if (s == undefined) s = 1.70158;
            return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
        },
        easeOutCubic: function (x, t, b, c, d) {
            return c * ((t = t / d - 1) * t * t + 1) + b;
        }
    });
})
</script>
</body>
</html>









附件:下载该文件资源,减少时间成本(增值服务)
留言
该资源可下载
File Source
.rar
480.60 KB
jquery特效7
最新结算
jquery虚拟键盘中文打字效果js代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
jquery虚拟键盘中文打字效果js代码
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
HTML5实现CSS滤镜图片切换特效代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
jQuery头像裁剪插件cropbox js代码
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
jQuery头像裁剪插件cropbox js代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
jQuery+css3实现信封效果
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
我们力求给您提供有用的文章,再此基础上,会附加营收资源,不做任何广告,让平台可以更好发展 若您发现您的权利被侵害,或使用了您的版权,请发邮件联系 sunlifel@foxmail.com ggbig觉得 : 不提供源码的文章不是好文章
合作伙伴
联系我们
  • QQ:21499807
  • 邮箱:sunlifel@foxmail.com
  • QQ扫一扫加QQ
    QQ扫一扫
Copyright 2023-2024 ggbig.com·皖ICP备2023004211号-1
打赏文章