搜索
首页web前端js教程JS自动适应的图片弹窗实例_javascript技巧

复制代码 代码如下:

/************************************自动适应的图片弹窗*********************************/
var autoImg=function(argcs){/*调整图片大小,等比例缩放argcs['maxHeight']=>最大高度,argcs['maxWidth']=>最大宽度,argcs['height']=>图片高度,argcs['width']=>图片宽度*/
                var _maxHeight='';
                var _maxWidth='';
                var _newSize=[];

                if(argcs['maxHeight']){
                    _maxHeight=argcs['maxHeight'];
                    }
                if(argcs['maxWidth']){
                    _maxWidth=argcs['maxWidth'];
                    }
                if(!argcs['height']){
                    throw new Error('height未指定');
                    }
                if(!argcs['width']){
                    throw new Error('width未指定');
                    }
                if(argcs['height']>argcs['width']||argcs['height']==argcs['width']){//高度不小于宽度的情况
                        if(argcs['height']>=_maxHeight){
                                _newSize['height']=_maxHeight;
                                _newSize['width']=(_maxHeight/argcs['height'])*argcs['width'];
                            }else{
                                _newSize['width']=argcs['width'];
                                _newSize['height']=argcs['height'];
                                }
                        return _newSize;
                    }
               if(argcs['width']>argcs['height']){//宽度大于高度的情况
                       if(argcs['width']>=_maxWidth){
                                _newSize[ '宽度']=_maxWidth;
                                _newSize['height']=(_maxWidth/argcs['width'])*argcs['height'];
                            }else{
                                _newSize['width']=argcs['width'];
                                _newSize['height']=argcs['height'];
                                }
                        return _newSize;
                    }               
                }

    var imgBox=function(imgSrc){            
           
           var winImg=new popBox({//图片弹窗
                ID:'imgBox',
                bgColor :'#a3c90e',
                width:906,
                moveHandle:false,
                closeButton:false,
                height:'auto',
                次:250,
                锁:true,
                内容:'',
                阴影:true,
                位置:'center',
                displayCallBack:function(){
                                       $('body').append('JS自动适应的图片弹窗实例_javascript技巧');                     $('img[id=loading]').css('z-index',110000); css({position:'absolute',left:$(window).scrollLeft() ($(window).width())/2-($('img[id=loading]').width())/ 2-22,顶部:$(window).scrollTop() ($(window).height()/2-($('img[id=loading]').width())/2)});
                    /************图片预加载,重新调整窗口大小及位置**************/
                    var img=new Image();
                    var _imgWidth=0;
                    var _imgHeight=0;
                     img.src=imgSrc;//为img对象添加地址
                                      // console.log(imgSrc);
                                        /*************************图片加载完成之后***************************/
                   img.onload=function(){
                                                $('img[id=loading]').remove();
                        _imgWidth=img.width;
                        _imgHeight=img.height;
                        var argcs=[];
                        var winWidth=$(window).width();
                        argcs['maxHeight']=750;//最大高度
                       argcs['maxWidth']=900;//最大宽度
                        argcs['height']=_imgHeight;
                        argcs['width']=_imgWidth; ('#' winImg.ID).css({宽度:newWH['宽度'],高度:newWH['高度'],top:parseInt($(document).scrollTop()) parseInt(($(window).height()-newWH['高度'])/ 2),left:$(document).scrollLeft() parseInt(winWidth/2)-parseInt(newWH['width']/2)});
                        $('#' winImg.ID).html('JS自动适应的图片弹窗实例_javascript技巧');
                        /************图片预加载,重新调整窗口大小及位置**************/

                        $('#' winImg.ID '_bg').css('光标','指针').click(function(){
winImg.kill();
                           });
                        };
                                        /*************************图片加载完成之后***************************/ 
                   },
                unDisplayCallBack:function(){

                     },
                KillCallBack:function(){
                    }
                } );
                winImg.dispaly();
    }

popBox代码
复制代码代码如下:

//若使用移动功能,请先导入jQuery移动UI组件
var popBox=function(settings){//弹窗函数settings=[]
        //alert(typeof settings['width']);
        //alert(settings['displayCallBack']);
        /************************本类私有变量*****************************/
        /*******************默认值*****************/
        var _shadow=true;//是否有遮罩true/false
        var _closeButton=false;//关闭按钮false/dom元素
        var _killButton=false;//kill按钮false/dom元素
        var _moveHandle=false;//拖动手柄false/dom元素
        var _width=650;//宽,
        var _bgColor='#FFF';//背景样式
        var _height='auto';//高
        var _content='没有内容';//内容
        var _position='center';/*位置topLeft,topCenter,topRight,center,bottomLeft,bottomRight,bottomCenter*/
        var _lock=true;//是否锁定
        var _times=500;//显示,隐藏的时间
        var _displayCallBack=function(){//dispaly回调函数
                alert('display');
            }
        var _unDisplayCallBack=function(){//unDispaly回调函数
                alert('unDisplay');
            }
        var _beforeKillCallBack=function(){
                alert('beforeKill');
            }//kill之前的回调函数
        var _killCallBack=function(){//kill回调函数
                alert('kill');
            }
        /*******************默认值*****************/
        if(settings['closeButton']!==undefined){
            //alert('shadow');
            _closeButton=settings['closeButton'];
            }   
        if(settings['killButton']!==undefined){
            //alert('shadow');
            _killButton=settings['killButton'];
            }
        if(settings['moveHandle']!==undefined){
            //alert('shadow');
            _moveHandle=settings['moveHandle'];
            }               
        /******************获得设置值********************/
        /**设置['阴影']!=' ' && 设置['阴影']!=未定义*/
        if(settings['shadow']!==undefined){
            //alert('shadow');
            _shadow=settings['shadow'];
            }
        if(settings['bgColor']!==undefined){
            //alert('shadow');
            _bgColor=settings['bgColor'];
            }
        if(settings['width']!==undefined){
            _width=settings['width'];
            }
        if(settings['height']!==undefined){
            _height=settings['height'];
            }
        if(settings['content']!==undefined){
            _content=settings['content'];
            }
        if(settings['position']!==undefined){
            _position=settings['position'];
            }
        if(settings['times']!==undefined){
            _times=settings['times'];
            }
        if(settings['lock']!==undefined){
            _lock=settings['lock'];
            }
        if(settings['displayCallBack']!=undefined){
            //alert('此处');
            _displayCallBack=settings['displayCallBack'];
            }       
        if(settings['unDisplayCallBack']!==undefined){
            _unDisplayCallBack=settings['unDisplayCallBack'];
            }   
        if( settings['beforeKillCallBack']!==undefined){
            _beforeKillCallBack=settings['beforeKillCallBack'];
            }
        if( settings['killCallBack']!==undefined){
            _killCallBack=settings['killCallBack'];
            }

        //alert(settings['shadow']);
        //alert(_shadow);
        /************************本类私有变量******************************/

        

        /*********************本类内部变量********************/   
        var _this=this;             
        var _baseZindex=10000;
        var _domWidth=$(document).width();
        var _domHeight=$(document).height();
        /********************本类内部变量*******************/

        
        /********************本类私有函数**********************/
        var _getZindex=function(){/*获得z-index->首先遍历网页div元素ID中含有popBox的DOM,获得数量,然后本弹窗背景z-index=基数+当前数量+1,弹框z-index=基数+当前数量+2*/
                var _len=$('body').children('div').length;
                var _countDiv=0;
                var _divObj=$('body').children('div');
                var _reg=/^popBox_/;//正则表达式
                for(var i=0;i<_len>                    if(_reg.test(_divObj.eq(i).attr('ID'))){
                            _countDiv+=1;
                        }
                    }
                return _countDiv;//返回已有弹框的数量
            }
        var _getWinZindex=function(){//获得弹窗的z-index
                var _winZindex=_baseZindex+_getZindex()+2;
                return _winZindex;
            }
        var _geWinBgZindex=function(){//获得弹窗背景的z-index
                var _winBgZindex=_baseZindex+_getZindex()+1;
                return _winBgZindex;                
            }
        var _renderBg=function(){//渲染背景  www.jb51.net
                var _winBgZindex=_geWinBgZindex();
                //alert($(document).height());
                $('body').append('
');//在body中插入一个半透明的背景
                $('#'+_this.ID+'_bg').addClass('popBox_bg').css({height:_domHeight,width:_domWidth,opcity:0}).css('z-index',_winBgZindex).fadeTo(_times,0.7);
            }
        var _creatWin=function(){//创建窗体
                $('body').append('
'); 양식 초기화
          var _winZindex=_getWinZindex();                                   ​ _transHeight='auto'; bgColor}).css('z-index',_winZindex);
if(_lock==false){
{
                    $('#' _this.ID).children(_moveHandle).css('cursor','move');                                                              //경고($( ' #' _this.ID).children(_moveHandle).html());
                                                                         | ight,centerLeft,center,centerRight,bottomLeft,bottomCenter,bottomRight*/
var _windowHeight =parseInt($(window).height());
var _windowWidth =parseInt($(window).width());
                                                 seInt($ (문서).scrollTop()) parseInt(($( window).height()-$('#' _this.ID).height())/2);
                $('#' _this.ID) .css({top:_top 'px',left: _왼쪽 'px'});
                                                                                               .ID).append(content)
                             var bindevent = function () {// 绑定事件
if (_this.status! == 'kill'&& _ this.status! == 'init') {
if (_closebutton! == intfefined && _ closeButton !==' '&&_closeButton!==false){
                           $('#' _this.ID ' ' _closeButton).css('cursor','pointer').live('click',function(e){
                          _this.unDisplay()
                        });                         
                      }//若设置了关闭(close)按钮
                     if(_killButton!==undefound&&_killButton!=='&&_killButton!==false) {
                           $('#' _this.ID ' ' _killButton ).css('cursor','pointer').live('click',function(e){
                          _this.kill();
                         });                         
                     }//若设置了杀死(kill)按钮
                 }
               if(_lock==false){ >                    $('#' _this.ID).draggable({취소:'' });
                  }
            }       
        /***********************이 클래스의 개인 기능*****************/

        
        /**************************이 클래스의 공개 기능*******************/
        this.status='init';//当前状态init->初始化状态,display->display状态,undisplay->undisplay状态,kill->kill状态
        this.ID='';
        var _ID=settings['ID'];
        if(_ID==' '||(typeof _ID)==undefine){
            throw new Error('ID不能为空');
            }else{
               this.ID='popBox_' _ID;
                }
this.display=function(){//표시 함수, 상태가 init 또는 kill인 경우 페이지를 다시 렌더링합니다.
//alert(_this.status)
if(_this.status= ='init' ||_this.status=='kill'){
                                                                                   > ~ ~ > ~ > //alert(_this.status);
binEvent();
}
this.kill=function(){//완전히 제거
//alert(_this.status); //경고(_this .status);
                                                                                   > ~                           
this.unDisplay=function(){//숨겨진 함수
if(_this.status=='init'||_this.status=='kill'){
throw new Error('잘못된 연산 , 현재 상태에서는 표시 취소가 허용되지 않습니다.')       🎜>               $('#' _this.ID).fadeOut( _times)
$('#' _this.ID '_bg').fadeOut(_times) );
_this.status='표시 해제'; 🎝>*/

                                                                                                                                   길이); ,
closeButton :false,
높이:'자동',
회:200,
잠금:true,
내용:$('#errorBoxContent').html(),
그림자:true,
위치:' center',
displayCallBack:function(){
$('#' errorObj.ID).find('.errorMessage').html()
$('# ' errorObj.ID). find('.errorMessage').html(errorMsg);
                                 $('#' errorObj.ID).find('.errorConfirm input').click(function(){
//alert('here ');
                   errorObj.kill();                                DisplayCallBack:function(){
                           > >>                  🎜>         })
errorObj.dispaly()
}//오류 팝업 창

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
超简单!用 Python 为图片和 PDF 去掉水印超简单!用 Python 为图片和 PDF 去掉水印Apr 12, 2023 pm 11:43 PM

网上下载的 pdf 学习资料有一些会带有水印,非常影响阅读。比如下面的图片就是在 pdf 文件上截取出来的,今天我们就来用Python解决这个问题。安装模块PIL:Python Imaging Library 是 python 上非常强大的图像处理标准库,但是只能支持 python 2.7,于是就有志愿者在 PIL 的基础上创建了支持 python 3的 pillow,并加入了一些新的特性。pip install pillow pymupdf 可以用 python 访问扩展名为*.pdf、

PHP和GD库实现图片裁剪的方法PHP和GD库实现图片裁剪的方法Jul 14, 2023 am 08:57 AM

PHP和GD库实现图片裁剪的方法概述:图片裁剪是网页开发中常见的需求之一,它可以用于调整图片的尺寸,剪裁不需要的部分,以适应不同的页面布局和展示需求。在PHP开发中,我们可以借助GD库来实现图片裁剪的功能。GD库是一个强大的图形库,可提供一系列函数来处理和操控图像。代码示例:下面我们将详细介绍如何使用PHP和GD库来实现图片裁剪。首先,确保你的PHP环境已经

PS AI修图免费平替来了!Stability AI又放大招,核弹级更新一键扩图PS AI修图免费平替来了!Stability AI又放大招,核弹级更新一键扩图Jun 12, 2023 pm 07:27 PM

此前,PS的重建图像功能就让人无比振奋,让无数人惊呼今天,StabilityAI又放大招了。它联合Clipdrop推出了UncropClipdrop——一个终极图像比例编辑器。从Uncrop这个名字上,我们就能看出它的用途。它是一个AI生成的「外画」工具,通过创建扩展背景,这个工具可以补充任何现有照片或图像,来更改任何图像的比例。敲黑板:通过Clipdrop网站,就可以免费试用这个工具了,无需登录!比例任意调,满意为止Uncrop基于StabilityAI的文本到图像模型StableDiffus

如何使用 Vue 实现图片预加载?如何使用 Vue 实现图片预加载?Jun 25, 2023 am 11:01 AM

在网页开发中,图片预载是一种常见的技术,可以提升用户的体验感。当用户浏览网页时,图片可以提前下载并加载,减少图片加载时的等待时间。在Vue框架中,我们可以通过一些简单的方法来实现图片预载。本文将介绍Vue中的图片预载技术,包括预载的原理、实现的方法和使用注意事项。一、预载的原理首先,我们来了解一下图片预载的原理。传统的图片加载方式是等到图片全部下载完成才显示

vue报错找不到图片怎么办vue报错找不到图片怎么办Nov 19, 2022 pm 05:01 PM

vue报错找不到图片的解决办法:1、修改配置文件,将绝对路径改为相对路径;2、将图片作为模块加载进去,并将图片放到static目录下;3、将imageUrls引入响应的vue文件中,解析引用即可。

如何在uniapp中实现图片滤镜效果如何在uniapp中实现图片滤镜效果Jul 04, 2023 am 11:05 AM

如何在uniapp中实现图片滤镜效果在移动应用开发中,图片滤镜效果是一种常见且受用户喜爱的功能之一。而在uniapp中,实现图片滤镜效果也并不复杂。本文将为大家介绍如何通过uniapp实现图片滤镜效果,并附上相关代码示例。导入图片首先,我们需要在uniapp项目中导入一张图片,以供后续滤镜效果的处理。可以在项目的资源文件夹中放置一张命名为“filter.jp

php写图片不显示不出来怎么办php写图片不显示不出来怎么办Nov 14, 2022 am 10:17 AM

php写图片不显示不出来的解决办法:1、找到并打开php.ini文件;2、找到“extension=php_gd2.dll”,并将前面的分号去掉;3、重新启动服务器;4、在绘图前清一下缓存即可。

AI去除马赛克,可还行?AI去除马赛克,可还行?Apr 09, 2023 pm 07:11 PM

哈喽,大家好。你有没有想过用 AI 技术去除马赛克?仔细想想这个问题还挺难的,因为我们之前使用的 AI 技术,不管是人脸识别还是OCR识别,起码人工能识别出来。但如果给你一张打上马赛克的图片,你能把它复原吗?显然是很难的。如果人都无法复原,又怎能教会计算机去复原呢?还记得前几天我写的一篇《用AI生成头像​》文章吗。在那篇文章中,我们训练了一个DCGAN模型,它可以从任意随机数生成一个图像。随机数作为像素生成的噪声图模型从随机数生成正常头像DCGAN​包含生成器模型和判别器模型​两个模型组成,生成

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前By尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前By尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
4 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )专业的PHP集成开发工具

VSCode Windows 64位 下载

VSCode Windows 64位 下载

微软推出的免费、功能强大的一款IDE编辑器

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器