您好,欢迎来到保捱科技网。
搜索
您的当前位置:首页简单漂亮的js弹窗可自由拖拽且兼容大部分浏览器_javascript技巧

简单漂亮的js弹窗可自由拖拽且兼容大部分浏览器_javascript技巧

来源:保捱科技网


简单漂亮的js弹窗 - 自由拖拽
代码如下:




简单漂亮的js弹窗 - 自由拖拽


//作者:zhao jinhan
//时间: 2013年10月22日
//邮箱:xb_zjh@126.com
function drag(o,s)
{
//drag(obj [,scroll]);
//obj:对象的id或对象本身;
//scroll(可选):对象是否随窗口拖动而滑动,默认为否

if (typeof o == "string") o = document.getElementById(o);
o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;
o.orig_y = parseInt(o.style.top) - document.body.scrollTop;
o.orig_index = o.style.zIndex;

o.onmousedown = function(a)
{
this.style.zIndex = 10000;
var d=document;
if(!a)a=window.event;
var x = a.clientX+d.body.scrollLeft-o.offsetLeft;
var y = a.clientY+d.body.scrollTop-o.offsetTop;

d.ondragstart = "return false;"
d.onselectstart = "return false;"
d.onselect = "document.selection.empty();"

if(o.setCapture)
o.setCapture();
else if(window.captureEvents)
window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);

d.onmousemove = function(a)
{
if(!a)a=window.event;
o.style.left = a.clientX+document.body.scrollLeft-x;
o.style.top = a.clientY+document.body.scrollTop-y;
o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;
o.orig_y = parseInt(o.style.top) - document.body.scrollTop;
}

d.onmouseup = function()
{
if(o.releaseCapture)
o.releaseCapture();
else if(window.captureEvents)
window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
d.onmousemove = null;
d.onmouseup = null;
d.ondragstart = null;
d.onselectstart = null;
d.onselect = null;
o.style.cursor = "normal";
o.style.zIndex = o.orig_index;
}
}

if (s)
{
var orig_scroll = window.onscroll?window.onscroll:function (){};
window.onscroll = function ()
{
orig_scroll();
o.style.left = o.orig_x + document.body.scrollLeft;
o.style.top = o.orig_y + document.body.scrollTop;
}
}
}

var title = '提示标题';
var message='提示内容';
var TrueEvent='';
var CancelEvent='';
var CloseEvent='';
function dialogalert(title, message, TrueEvent, CancelEvent, CloseEvent) {
$("#divBackground").removeClass("hidden");
$("#divMaincontent").removeClass("hidden");

$("#alertTitle").html(title);
$("#alertContent").html(message);

$("#btnSure").click(function () {
$("#divBackground").addClass("hidden");
$("#divMaincontent").addClass("hidden");
$("#btnSure").unbind("click");
if (TrueEvent) {
//确认之后跳转url
window.location.href = TrueEvent;
}

}); //确定

$("#btnCancel").click(function () {
$("#divBackground").addClass("hidden");
$("#divMaincontent").addClass("hidden");
$("#btnCancel").unbind("click");
if (CancelEvent) {
//取消之后跳转url
window.location.href = CancelEvent;
}
});//取消

$("#btnClose").click(function () {
$("#divBackground").addClass("hidden");
$("#divMaincontent").addClass("hidden");
$("#btnClose").unbind("click");
if (CloseEvent) {
//关闭之后跳转url
window.location.href = CloseEvent;
}

});//X关闭
}

$(function(){
drag("divMaincontent");
dialogalert("弹窗标题","弹窗信息",'http://www.baidu.com/','http://www.icode100.com/','http://bbs.icode100.com/');
});





提示信息


提示


今日秒杀已售罄




确认取消









效果图片:

images/里面的图片:

dialog_blue.gif:

pm_bg.png

文件包下载:
http://www.gxlcms.com/jiaoben/112059.html

Copyright © 2019- baoaiwan.cn 版权所有 赣ICP备2024042794号-3

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务