javascript模仿msgbox提示效果代码_javascript技巧
程序员文章站
2022-04-30 15:45:41
...
复制代码 代码如下:
//前任作者:http://www.moozi.net
//修改:hh13774978@126.com,rayking
function $(str){
return document.getElementById(str);
}
function _(str){
return document.getElementsByTagName(str);
}
function msg(boxtitle,boxtype,boxwidth,msg,url){
$("msg_div_main").style.width = boxwidth;
$("msg_div_main").style.left = (_("body")[0].clientWidth - boxwidth) / 2;
$("msg_div_main").style.top = (_("body")[0].clientHeight - 220) / 2;
var msg_div_main_but_tmp = "
"
+ "";
switch(boxtype * 1){
case 1:
$("msg_div_main_content").innerHTML = msg + msg_div_main_but_tmp;
//$("msg_div_main_but").focus();
break;
case 2:
$("msg_div_main_content").innerHTML = msg + msg_div_main_but_tmp
+ " ";
//$("msg_div_main_but").focus();
break;
case 3:
$("msg_div_main_content").innerHTML = msg;
break;
defualt:
$("msg_div_main_content").innerHTML = msg;
break;
}
$("msg_div_main_title").innerHTML = boxtitle;
$("msg_div_main").style.zIndex = 200;
$("msg_div_main").style.display = "";
if(document.all){ //IE
if(!$("msg_div_all_Iframe"))
{
document.body.appendChild(document.createElement(""));
}
$("msg_div_all").style.zIndex = 100;
$("msg_div_all").style.display = "";
$("msg_div_all").oncontextmenu = function()
{
return false;
}
$("msg_div_all_Iframe").style.zIndex = 99;
$("msg_div_all_Iframe").style.display = "";
$("msg_div_all_Iframe").oncontextmenu = function()
{
return false;
}
}else{
$("msg_div_all").style.zIndex = 100;
$("msg_div_all").style.display = "";
$("msg_div_all").oncontextmenu = function()
{
return false;
}
}
$("msg_div_main").oncontextmenu = function(){
return false;
}
}
function msg_close_tmp_biyuan(){
$('msg_div_all').style.display='none';
$('msg_div_main').style.display='none';
if(document.all){
$('msg_div_all_Iframe').style.display='none';}
}
//加入对话框移动代码
/* 鼠标拖动 */
var oDrag = "";
var ox,oy,nx,ny,dy,dx;
function drag(e,o){
var e = e ? e : event;
var mouseD = document.all ? 1 : 0;
if(e.button == mouseD)
{
if (o.parentNode)
{
oDrag = o.parentNode;
}
else{oDrag = o;}
ox = e.clientX;
oy = e.clientY;
}
}
function dragPro(e){
if(oDrag != "")
{
//var obj=document.getElementById("msg");//拖动的id
var obj=oDrag;//拖动的id
var e = e ? e : event;
obj.style.position = 'absolute';
dx = parseInt(obj.style.left);
dy = parseInt(obj.style.top);
if(isNaN(dx)){dx=0;}
if(isNaN(dy)){dy=0;}
nx = e.clientX;
ny = e.clientY;
obj.style.left = (dx + ( nx - ox )) + "px";
obj.style.top = (dy + ( ny - oy )) + "px";
ox = nx;
oy = ny;
}
}
document.onmouseup = function(){oDrag = "";}
document.onmousemove = function(event){dragPro(event);}
document.writeln(""
+ ""
+""
+ " ");
在线演示
打包下载
推荐阅读
-
纯js实现的论坛常用的运行代码的效果_javascript技巧
-
一个简单的js动画效果代码_javascript技巧
-
js 文本滚动效果的实例代码_javascript技巧
-
inputSuggest文本框输入时提示、自动完成效果(邮箱输入自动补全插件)_javascript技巧
-
js实现的定时关闭页面或定时提醒效果代码_javascript技巧
-
用javascript来实现动画导航效果的代码_javascript技巧
-
JavaScript 浮动定位提示效果实现代码_javascript技巧
-
一个鼠标移动滑出层效果的实现代码_javascript技巧
-
javascript返回顶部效果(自写代码)_javascript技巧
-
JS仿淘宝实现的简单滑动门效果代码_javascript技巧