网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

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

这篇文章主要介绍如何基于jQuery插件jqzoom实现的图片放大镜效果,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

成都创新互联专注于企业营销型网站建设、网站重做改版、松桃网站定制设计、自适应品牌网站建设、成都h5网站建设购物商城网站建设、集团公司官网建设、成都外贸网站建设公司、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为松桃等各大城市提供网站开发制作服务。

jqzoom插件实现图片放大镜效果。

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

图1.1jqzoom插件实现图片放大镜效果

1、引入jqurty和jqzoom插件


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

/*jQzoom*/
.jqzoom{
  border:1px solid #BBB;
  float:left;
  position:relative;
  padding:0px;
  cursor:pointer;
}
div.zoomdiv {
  z-index:  999;
  position        : absolute;
  top:0px;
  left:0px;
  width          : 200px;
  height         : 200px;
  background: #ffffff;
  border:1px solid #CCCCCC;
  display:none;
  text-align: center;
  overflow: hidden;
}
div.jqZoomPup {
  z-index         : 999;
  visibility       : hidden;
  position        : absolute;
  top:0px;
  left:0px;
  width          : 50px;
  height         : 50px;
  border: 1px solid #aaa;
  background: #ffffff url(/images/shopping/zoomlens.gif) 50% top no-repeat;
  opacity: 0.5;
  -moz-opacity: 0.5;
  -khtml-opacity: 0.5;
  filter: alpha(Opacity=50);
}

3、编写HTML代码


  

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

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

/*使用jqzoom*/
$(function() {
  $(".jqzoom").jqueryzoom({
    xzoom: 300, //放大图的宽度(默认是 200)
    yzoom: 300, //放大图的高度(默认是 200)
    offset: 10, //离原图的距离(默认是 10)
    position: "right", //放大图的定位(默认是 "right")
    preload: 1
  });
});

附件

附件1:jQuery.jqzoom.js

//**************************************************************
// jQZoom allows you to realize a small magnifier window,close
// to the image or images on your web page easily.
//
// jqZoom version 2.2
// Author Doc. Ing. Renzi Marco(www.mind-projects.it)
// First Release on Dec 05 2007
// i'm looking for a job,pick me up!!!
// mail: renzi.mrc@gmail.com
//**************************************************************
(function($){
    $.fn.jqueryzoom = function(options){
    var settings = {
        xzoom: 200,   //zoomed width default width
        yzoom: 200,   //zoomed div default width
        offset: 10,   //zoomed div default offset
        position: "right" ,//zoomed div default position,offset position is to the right of the image
        lens:1, //zooming lens over the image,by default is 1;
        preload: 1
      };
      if(options) {
        $.extend(settings, options);
      }
      var noalt='';
      $(this).hover(function(){
      var imageLeft = $(this).offset().left;
      var imageTop = $(this).offset().top;
      var imageWidth = $(this).children('img').get(0).offsetWidth;
      var imageHeight = $(this).children('img').get(0).offsetHeight;
      noalt= $(this).children("img").attr("alt");
      var bigimage = $(this).children("img").attr("jqimg");
      $(this).children("img").attr("alt",'');
      if($("div.zoomdiv").get().length == 0){
      $(this).after("
");       $(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("sdsdssdsd");     $(this).each(function(){     var imagetopreload= $(this).children("img").attr("jqimg");     var content = jQuery('div.jqPreload'+count+'').html();     jQuery('div.jqPreload'+count+'').html(content+'');     });     }     } })(jQuery); function MouseEvent(e) {    this.x = e.pageX;    this.y = e.pageY; }

附件2:放大镜图标(zoomlens.gif)

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

以上是“如何基于jQuery插件jqzoom实现的图片放大镜效果”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!


本文标题:如何基于jQuery插件jqzoom实现的图片放大镜效果
标题URL:http://bjjierui.cn/article/iihjos.html