zoukankan      html  css  js  c++  java
  • 缩略图预览mini库

    这是一个依赖jquery的mini库文件,主要用于缩略图的预览:
    如下一张缩略图,实际图片大小比这个要大许多

    利用这个jquery插件,只需将要缩略图、原图切换的元素使用$('jquery选择器image').viewImage();就可以点击切换显示这张图片。
    简单易用。点击效果图如下:
    下面贴出完整代码:极其剪短
    (function($,factory){ if(typeof define === 'object' && typeof require === 'object'){ define([ 'jquery' ],function($){ factory() }); }else{ factory($); } })(jQuery,function(){ var ImageViewer = function(element){ var naturalHeight, naturalWidth; this.$element = $(element); this.naturalWidth = element.naturalWidth; this.naturalHeight = element.naturalHeight; this.$viewerContainer = $('.viewer-container'); this.$viewerContainer.on('click',this.hide.bind(this)); this.$element.on('click',this.show.bind(this)); }; ImageViewer.prototype.show=function(){ this.$viewerContainer.empty() .css({ 'zIndex':1, 'height',this.naturalHeight+'px' }).append(this.$element.get(0).outerHTML) .show().find('img').css({ 'cursor':'zoom-out', 'maxHeight':'100%' }); }; ImageViewer.prototype.hide=function(){ this.$viewerContainer.empty().hide(); }; function Plugin(){ var $viewerContainer = $('<div class="viewer-container"></div>'); $viewerContainer.css({ position:'fixed', left:0, right:0, top:0, bottom:0, margin:'auto', 'textAlign':'center', 'maxHeight':'100%', 'zIndex':-1 }); $viewerContainer.appendTo(document.body); return this.each(function(){ new ImageViewer(this); }); } $.fn.viewImage = Plugin; });

    希望对任何需要的人有所帮助。。。。啦啦啦

  • 相关阅读:
    高性能SQL编码规范
    识别SQL Server 性能杀手
    centOS7安装nginx
    linux安装apache
    算术表达式的前缀表达式,中缀表达式和后缀表达式
    有特殊字符的JSON串
    sqlserver 找到执行慢的sql
    SQL索引建立遵守六大铁律
    [SQL Server 2005/2008] select语句中指定索引
    ubuntu下vsftpd虚拟用户配置
  • 原文地址:https://www.cnblogs.com/lds2014/p/5220545.html
Copyright © 2011-2022 走看看