1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
this .mouse_try= function (mouse_box,obversepic,facade){
$(mouse_box).mousemove( function (e){
var
event = e || window.event; //window.event 对象可以监听键盘和鼠标的一些动作。可以获取鼠标当前的位置。设置其他对象的坐标就可以实现跟随
//定义最大宽度和高度
maxW=$( this ).width();
maxH=$( this ).height();
//鼠标跟随返效果
obverseL=$( this ).width()-event.screenX;
obverseT=$( this ).height()-event.screenY;
//跟随对象父层到页面窗口的位置
parent_offset = $(facade).offsetParent().offset();
facadeL = e.pageX+5-parent_offset.left;
facadeT=e.pageY+5-parent_offset.top;
$(obversepic).css({ ‘left‘ :obverseL+ ‘px‘ , ‘top‘ :obverseT+ ‘px‘ });
//判断鼠标跟随效果移动的范围
if (facadeL>maxW-$(facade).width()){
$(facade).css({ ‘left‘ :maxW-$(facade).width()+ ‘px‘ });
}
else {
$(facade).css({ ‘left‘ :facadeL+ ‘px‘ });
}
if (facadeT > maxH-$(facade).height()){
$(facade).css({ ‘top‘ :maxH-$(facade).height()+ ‘px‘ });
}
else {
$(facade).css({ ‘top‘ :facadeT+ ‘px‘ });
}
});
} |