http://bbs.blueidea.com/thread-2688074-1-1.html
如同Lightbox的效果那边,或者说和Windows关闭系统前的那一刻类似,为突出显示主题而采取的暗淡背景的方法在Web2.0的站点风格中被越来越多的使用。
(关于Lightbox:http://www.cnbruce.com/blog/showlog.asp?cat_id=34&log_id=1005 )
现在,当弹出千篇一律的Alert警告框被这样的一种方式取代时,给人的感觉是相当的新鲜的。
这样效果一:
1
<input type="button" value="点击这里" onclick="sAlert('测试效果<br>还可以直接书写HTML代码 <br>© 2006');" />
2
3
<script type="text/javascript" language="javascript">
4
//Author:Daviv
5
//Blog:http://blog.163.com/jxdawei
6
//Date:2006-10-28
7
//Email:jxdawei@gmail.com
8
function sAlert(str){
9
var msgw,msgh,bordercolor;
10
msgw=400;//提示窗口的宽度
11
msgh=100;//提示窗口的高度
12
bordercolor="#336699";//提示窗口的边框颜色
13
titlecolor="#99CCFF";//提示窗口的标题颜色
14
15
var sWidth,sHeight;
16
sWidth=document.body.offsetWidth;
17
sHeight=document.body.offsetHeight;
18
19
20
var bgObj=document.createElement("div");
21
bgObj.setAttribute('id','bgDiv');
22
bgObj.style.position="absolute";
23
bgObj.style.top="0";
24
bgObj.style.background="#777";
25
bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
26
bgObj.style.opacity="0.6";
27
bgObj.style.left="0";
28
bgObj.style.width=sWidth + "px";
29
bgObj.style.height=sHeight + "px";
30
document.body.appendChild(bgObj);
31
var msgObj=document.createElement("div")
32
msgObj.setAttribute("id","msgDiv");
33
msgObj.setAttribute("align","center");
34
msgObj.style.position="absolute";
35
msgObj.style.background="white";
36
msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
37
msgObj.style.border="1px solid " + bordercolor;
38
msgObj.style.width=msgw + "px";
39
msgObj.style.height=msgh + "px";
40
msgObj.style.top=(document.documentElement.scrollTop + (sHeight-msgh)/2) + "px";
41
msgObj.style.left=(sWidth-msgw)/2 + "px";
42
var title=document.createElement("h4");
43
title.setAttribute("id","msgTitle");
44
title.setAttribute("align","right");
45
title.style.margin="0";
46
title.style.padding="3px";
47
title.style.background=bordercolor;
48
title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
49
title.style.opacity="0.75";
50
title.style.border="1px solid " + bordercolor;
51
title.style.height="18px";
52
title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
53
title.style.color="white";
54
title.style.cursor="pointer";
55
title.innerHTML="关闭";
56
title.onclick=function(){
57
document.body.removeChild(bgObj);
58
document.getElementById("msgDiv").removeChild(title);
59
document.body.removeChild(msgObj);
60
}
61
document.body.appendChild(msgObj);
62
document.getElementById("msgDiv").appendChild(title);
63
var txt=document.createElement("p");
64
txt.style.margin="1em 0"
65
txt.setAttribute("id","msgTxt");
66
txt.innerHTML=str;
67
document.getElementById("msgDiv").appendChild(txt);
68
}
69
</script>
70

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

把SCRIPT做成一个JS文件就可以了。