鼠标跟随效果html,jQuery实现鼠标跟随效果

*{

margin:0;

padding:0;

}

img{

border:none;

}

.box{

width:660px;

position: relative;

}

.box .mark{

position: absolute;

width: 400px;

height: 300px;

display: none;

}

.box .mark img{

width: 100%;

}

.box img{

width: 150px;

float: left;

margin:5px;

}

misc.php?mod=attach&genre=editor&aid=e95708d565639d99576ae7cb00729334

realImg="http://www.qdfuns.com/misc.php?mod=attach&genre=editor&aid=5328802dc943fc046e109f70359add0a" alt=""/>

misc.php?mod=attach&genre=editor&aid=9e5459a7c0098c27adf4bdd73889caa9

realImg="http://www.qdfuns.com/misc.php?mod=attach&genre=editor&aid=846f4d1987765dc4cfd5a06fcdd2dcc1" alt=""/>

misc.php?mod=attach&genre=editor&aid=3cd1c8e301007f0c94850139ac79cb5a

realImg="http://www.qdfuns.com/misc.php?mod=attach&genre=editor&aid=747bf3f7092ebd2b0bf9fcd27e28bbe5" alt=""/>

misc.php?mod=attach&genre=editor&aid=f391169b2cf678aa6fd253cf40d9821d

realImg="http://www.qdfuns.com/misc.php?mod=attach&genre=editor&aid=fec8d2f20fad1f28d540337a831e89d0" alt=""/>

//1.鼠标移入哪张图片的时候,让他对应的大图显示;

//2.当鼠标在img中移动的时候,大图跟着走;

var $box=$('.box');

var $aImg=$box.children('img');

var $mark=$('.mark');

var $offset=$box.offset();

$aImg.mouseover(function(){

//当鼠标移入每张图片的时候,让mark显示,并且,让mark里面的img标签,src属性值为当前这个图片的realImg属性上拿到的值;

$mark.show().find('img').attr('src',$(this).attr('realImg'));

});

$aImg.mousemove(function(e){

//拿鼠标的x坐标,减去$box距离body的left位置;

var left= e.clientX-$offset.left+10;

var top= e.clientY-$offset.top+10;

$mark.css({left:left,top:top})

});

$aImg.mouseout(function(){

$mark.hide();

})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值