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

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

  • 相关阅读:
    团队-科学计算器-成员简介及分工
    团队-团队编程项目作业名称-需求分析
    《对软件工程课程的期望》
    《自我介绍》
    个人编程项目
    对软件工程课程的期望
    《自我介绍》
    结队-爬取大麦网近期演唱会信息-项目进度
    团队-排课系统-设计文档
    团队-排课系统-开发环境搭建过程
  • 原文地址:https://www.cnblogs.com/lds2014/p/5220545.html
Copyright © 2011-2022 走看看