前端之家收集整理的这篇文章主要介绍了
基于jQuery插件jqzoom实现的图片放大镜效果示例,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_502_0@本文实例讲述了基于jQuery插件jqzoom实现的图片放大镜效果。分享给大家供大家参考,具体如下:
@H_
502_0@jqzoom
插件实现
图片放大镜
效果。
<p style="text-align: center">@H_
403_4@

<p style="text-align: center">图1.1jqzoom
插件实现
图片放大镜
效果
@H_
502_0@
1、引入jqurty和jqzoom插件
<div class="jb51code">
<pre class="brush:js;">
<script src="/js/common/jquery-1.6.2.js" type="text/javascript">
<script src="/js/common/jquery.jqzoom.js" type="text/javascript">
");
}
if(settings.position == "right"){
if(imageLeft + imageWidth + settings.offset + settings.xzoom > screen.width){
leftpos = imageLeft - settings.offset - settings.xzoom;
}else{
leftpos = imageLeft + imageWidth + settings.offset;
}
}else{
leftpos = imageLeft - settings.xzoom - settings.offset;
if(leftpos < 0){
leftpos = imageLeft + imageWidth + settings.offset;
}
}
$("div.zoomdiv").css({ top: imageTop,left: leftpos });
$("div.zoomdiv").width(settings.xzoom);
$("div.zoomdiv").height(settings.yzoom);
$("div.zoomdiv").show();
if(!settings.lens){
$(this).css('cursor','crosshair');
}
$(document.body).mousemove(function(e){
mouse = new MouseEvent(e);
/*$("div.jqZoomPup").hide();*/
var bigwidth = $(".bigimg").get(0).offsetWidth;
var bigheight = $(".bigimg").get(0).offsetHeight;
var scaley ='x';
var scalex= 'y';
if(isNaN(scalex)|isNaN(scaley)){
var scalex = (bigwidth/imageWidth);
var scaley = (bigheight/imageHeight);
$("div.jqZoomPup").width((settings.xzoom)/scalex );
$("div.jqZoomPup").height((settings.yzoom)/scaley);
if(settings.lens){
$("div.jqZoomPup").css('visibility','visible');
}
}
xpos = mouse.x - $("div.jqZoomPup").width()/2 - imageLeft;
ypos = mouse.y - $("div.jqZoomPup").height()/2 - imageTop ;
if(settings.lens){
xpos = (mouse.x - $("div.jqZoomPup").width()/2 < imageLeft ) ? 0 : (mouse.x + $("div.jqZoomPup").width()/2 > imageWidth + imageLeft ) ? (imageWidth -$("div.jqZoomPup").width() -2) : xpos;
ypos = (mouse.y - $("div.jqZoomPup").height()/2 < imageTop ) ? 0 : (mouse.y + $("div.jqZoomPup").height()/2 > imageHeight + imageTop ) ? (imageHeight - $("div.jqZoomPup").height() -2 ) : ypos;
}
if(settings.lens){
$("div.jqZoomPup").css({ top: ypos,left: xpos });
}
scrolly = ypos;
$("div.zoomdiv").get(0).scrollTop = scrolly * scaley;
scrollx = xpos;
$("div.zoomdiv").get(0).scrollLeft = (scrollx) * scalex ;
});
},function(){
$(this).children("img").attr("alt",noalt);
$(document.body).unbind("mousemove");
if(settings.lens){
$("div.jqZoomPup").remove();
}
$("div.zoomdiv").remove();
});
count = 0;
if(settings.preload){
$('body').append("
");
$(this).each(function(){
var imagetopreload= $(this).children("img").attr("jqimg");
var content = jQuery('div.jqPreload'+count+'').html();
jQuery('div.jqPreload'+count+'').html(content+'