一、导 言
$.fn.zoom = function() {
var w = this.width();
var h = this.height();
var zimg = $( <img> , {
src : this.attr( src )
}).css({
position : absolute ,
left : 0,
top : 0,
opacity : 0
})
var moveZone = $( <div> ).css({
position : absolute ,
left : 0,
top : 0,
width : 100% ,
height : 100%
}).hover(
function() {
zimg.fadeTo(500, 1);
}, function() {
zimg.fadeTo(500, 0);
}).mousemove(
function(ev) {
zimg.css({
left : (w - zimg.width()) / w * ev.offsetX,
top : (h - zimg.height()) / h * ev.offsetY
});
});
this.wrap($( <div> ).css({
overflow : hidden ,
position : relative ,
width : w,
height : h
})).after(zimg, moveZone)
}
demo