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; });

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

  • 相关阅读:
    react native 学习资料整理
    yii cookie ,session 操作
    react native 的js 文件从哪里获取
    react native与现有的应用程序集成
    ubuntu 12.04 react-native 安装
    html ul li的学习
    CAGradientLayer的一些属性解析
    ubuntu 安装 swoole 和mac 安装swoole 扩展
    iOS React-Native入门指南之HelloWorld
    实现微信浏览器内打开App Store链接(已被和谐,失效了)
  • 原文地址:https://www.cnblogs.com/lds2014/p/5220545.html
Copyright © 2011-2022 走看看