Home Web Front-end JS Tutorial jquery.Jwin.js popup layer plug-in code based on jquery_jquery

jquery.Jwin.js popup layer plug-in code based on jquery_jquery

May 16, 2016 pm 05:53 PM
Pop-up layer

The code is as follows:

Copy the code The code is as follows:

(function ($) {
var imgdir = 'images/';//图片文件夹路径
var autoHide=false;//悬浮div是否自动隐藏
var hideType='hide';//隐藏的方式 可选参数 hide、slide、fade
var hideDelay=0;//悬浮div隐藏过程使用的时间
var hideTime=0;//悬浮div延迟隐藏时间
var zIndex=100;//多个div时获取焦点的div处于顶层
var showType='show';//悬浮div显示方式 可选参数 hide、slide、fade
var showTime=0;//悬浮div显示过程使用的时间
var showDelay=0;//悬浮div延迟显示的时间
//以下两个变量用于保证div被拖动后隐藏 再次打开后出现的位置仍然为首次出现的位置
var oldTop='';//保存div初次出现的top
var oldLeft='';//保存div初次出现的left
$.fn.extend({
Jwin:function(option){
var op=$.extend({
id:'',//悬浮div的id (必须)
title: '',//标题
message:'',//显示信息
elementId:'',//显示元素的id
url: '',//显示的页面地址
width: 400,//悬浮div的宽度
height: 300,//悬浮div的高度
//悬浮div显示参数
showType:'show',//悬浮div显示方式 可选参数 hide、slide、fade
showTime:0,//悬浮div显示过程使用的时间
showDelay:0,//悬浮div延迟显示的时间
//悬浮div隐藏参数
autoHide:false,//悬浮div是否自动隐藏
hideType:'hide',//隐藏的方式 可选参数 hide、slide、fade
hideTime:0,//悬浮div隐藏过程使用的时间
hideDelay:0,//悬浮div自动隐藏延迟时间
},option);

if(op.id==''){
alert("缺少WinId");
return;
}

autoHide=op.autoHide;
hideType=op.hideType;
hideDelay=op.hideDelay;
hideTime=op.hideTime;
showType=op.showType;
showTime=op.showTime;
showDelay=op.showDelay;
zIndex=zIndex+1;

var winEle=$("#"+op.id);
if(winEle.length==0){
this.width = parseInt(op.width);
this.height = parseInt(op.height);
var banner=this.JwinCreatBanner(op.id,this.width,op.title);
oldTop = this.height >= document.documentElement.clientHeight ? 0 : (document.documentElement.clientHeight-this.height)/2;
oldLeft = this.width >= document.body.clientWidth ? 0 : (document.body.clientWidth-this.width)/2;

win=$('
');
win.css({'position':'absolute','top':oldTop,'left':oldLeft,'width':(this.width+2),'zIndex':zIndex,'display':'none'});
win.html(banner);
win.find("#close").bind('click',function(){$(this).JwinClose(op.id);});
win.find("#bannerMiddle").bind('mousedown',function(){$(this).JwinMove(op.id);});

var container=$('
');
container.css({'float':'left','width':+this.width,'height':this.height,'word-break':'break-all','overflow-x':'hidden','overflow-y':'auto','border':'1px solid #1972e1','background-color':'#FFF','clear':'both'});

if(op.message.length>0){
container.append(op.message);
}
else if(op.url.length>0){
var iframe=$('');
iframe.css({'width':'100%','height':'100%','overflow':'visible','border':'0'});
iframe.attr('src',op.url);
container.append(iframe);
}
else if(op.elementId.length>0){
var element=$("#"+op.elementId);
if(element){
container.append(element);
element.show();
}
}

win.append(container);
$(document.body).append(win);
this.JwinShow(win);

//是否设置自动关闭
if(autoHide){
this.JwinHide(op.id);
}
}
else{
winEle.css({'zIndex':(winEle.css('zIndex')+2),'top':oldTop,'left':oldLeft});
this.JwinShow(winEle);
}
},

//创建标题
JwinCreatBanner:function(winId,width,title){
var bannerImddleWidth = width-47;//拖动部分div宽度为总宽度减去两边圆角宽度、关闭按钮宽度
var banner = '
';
banner += '
';
banner += '
'+title+'
';
banner += '
';
banner = '
';
banner = '
';
return banner;
},

//拖动
JwinMove:function(winId){
var floatWin=document.getElementById(winId);
zIndex=zIndex 1;
floatWin.style.zIndex=zIndex;
o=window.event.srcElement||window.event.target;
var d=document;
var a=window.event;
var x=a.layerX?a.layerX:a.offsetX;
var y=a.layerY?a.layerY:a.offsetY;
if(o.setCapture){
o.setCapture();
}
else if(window.captureEvents){
window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
}

d.onmousemove=function(a){
if(!a)a=window.event;
if(!a.pageX)a.pageX=a.clientX;
if(!a.pageY)a.pageY=a.clientY;
var tx=a.pageX-x,ty=a.pageY-y;
var maxx=document.documentElement.clientWidth-floatWin.clientWidth;
var maxy=document.documentElement.clientHeight-floatWin.clientHeight;
tx=(tx<0)?0:tx;
ty=(ty<0)?0:ty;
tx=(tx>maxx)?maxx:tx;
ty=(ty>maxy)?maxy:ty;
floatWin.style.left=tx;
floatWin.style.top=ty;
};

d.onmouseup=function(){
if(o.releaseCapture){
o.releaseCapture();
}
else if(window.captureEvents){
window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
}
d.onmousemove=null;
d.onmouseup=null;
};
},

//显示
JwinShow:function(win){
var t = showDelay;
switch(showType){
case 'slide':
setTimeout(function(){win.slideDown(showTime);}, t);
break;
case 'fade':
setTimeout(function(){win.fadeIn(showTime);},t);
break;
default:
setTimeout(function(){win.show();},t);
break;
}
},

//隐藏
JwinHide:function(winId,atonce){
var win = $("#" winId);
var t = atonce ? 0 : hideDelay;
switch(hideType){
case 'slide':
setTimeout(function(){win.slideUp(hideTime);}, t);
break;
case 'fade':
setTimeout(function(){win.fadeOut(hideTime);},t);
break;
default:
setTimeout(function(){win.hide();},t);
break;
}
},

//关闭
JwinClose:function(winId){
this.JwinHide(winId,true);
}
});
})(jQuery)
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to merge array elements with the same ID into one object using JavaScript? How to merge array elements with the same ID into one object using JavaScript? Apr 04, 2025 pm 05:09 PM

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

The difference in console.log output result: Why are the two calls different? The difference in console.log output result: Why are the two calls different? Apr 04, 2025 pm 05:12 PM

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

How to achieve parallax scrolling and element animation effects, like Shiseido's official website?
or:
How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? How to achieve parallax scrolling and element animation effects, like Shiseido's official website? or: How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? Apr 04, 2025 pm 05:36 PM

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

Can PowerPoint run JavaScript? Can PowerPoint run JavaScript? Apr 01, 2025 pm 05:17 PM

JavaScript can be run in PowerPoint, and can be implemented by calling external JavaScript files or embedding HTML files through VBA. 1. To use VBA to call JavaScript files, you need to enable macros and have VBA programming knowledge. 2. Embed HTML files containing JavaScript, which are simple and easy to use but are subject to security restrictions. Advantages include extended functions and flexibility, while disadvantages involve security, compatibility and complexity. In practice, attention should be paid to security, compatibility, performance and user experience.

Is JavaScript hard to learn? Is JavaScript hard to learn? Apr 03, 2025 am 12:20 AM

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

See all articles