基于jQuery插件jqzoom实现的图片放大镜效果示例

前端之家收集整理的这篇文章主要介绍了基于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">

@H_502_0@

2、应用官方网站给定的样式

@H_502_0@

3、编写HTML代码

@H_502_0@其中,在HTML代码添加插件自定义的jqimg属性,值为大图的文件路径。

@H_502_0@

4、查看官方网站的API使用说明,可以写出如下JS代码

@H_502_0@

附件

@H_502_0@附件1:jQuery.jqzoom.js

"); $(this).append("
"); } 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+'
@H_502_0@附件2:放大镜图标(zoomlens.gif)

@H_502_0@

@H_502_0@更多关于jQuery相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》及《

@H_
502_0@希望本文所述对大家jQuery程序设计有所帮助。

猜你在找的jQuery相关文章