利用layer实现放大图片的效果

引用layer.js

//小图

<a href="javascript:amplificationImg('图片名','图片地址')"><img src="" alt=""/></a>

//隐藏域 也就是放大以后的图片位置

<img alt="" style="display:none" id="displayImg" src="" />

//js方法体

function amplificationImg(name, url) {
   $("#displayImg").attr("src", url);
   var height = $("#displayImg").height();//拿的图片原来宽高,建议自定义宽高
   var width = $("#displayImg").width();
   layer.open({
      type: 1,
      title: false,
      closeBtn: 0,
      shadeClose: true,
      area: [width + 'px', height + 'px'], //宽高
      content: "<img alt=" + name + " title=" + name + " src=" + url + " />"
   });
}
posted @ 2018-02-07 13:59  Teler  阅读(251)  评论(0)    收藏  举报