Skip to content

Commit 8bb9133

Browse files
committed
定制皮肤
1 parent e3fe1f3 commit 8bb9133

File tree

8 files changed

+263
-0
lines changed

8 files changed

+263
-0
lines changed

8.1 定制皮肤/css/base.css

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,
2+
form,fieldset,input,textarea,p,blockquote,th,td {
3+
padding: 0;
4+
margin: 0;
5+
}
6+
table {
7+
border-collapse: collapse;
8+
border-spacing: 0;
9+
}
10+
fieldset,img {
11+
border: 0;
12+
}
13+
address,caption,cite,code,dfn,em,strong,th,var {
14+
font-weight: normal;
15+
font-style: normal;
16+
}
17+
ol,ul {
18+
list-style: none;
19+
}
20+
caption,th {
21+
text-align: left;
22+
}
23+
h1,h2,h3,h4,h5,h6 {
24+
font-weight: normal;
25+
font-size: 100%;
26+
}
27+
q:before,q:after {
28+
content:'';
29+
}
30+
abbr,acronym { border: 0;
31+
}

8.1 定制皮肤/css/window.css

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
.btn{
2+
text-decoration: none;
3+
padding:5px 10px;
4+
width: 50px;
5+
text-align: center;
6+
display: block;
7+
margin: 100px;
8+
background: #ddd;
9+
}
10+
11+
.window_boundingBox{
12+
position: fixed;
13+
border: 1px solid #ddd;
14+
width: 500px;
15+
height: 300px;
16+
left: 50%;
17+
margin-left: -250px;
18+
top:100px;
19+
box-shadow: 0 0 12px #888;
20+
}
21+
22+
.window_alertBtn{
23+
width: 100px;
24+
position: absolute;
25+
bottom: 10px;
26+
left: 50%;
27+
margin-left: -50px;
28+
}
29+
30+
.window_header{
31+
background: #999;
32+
color: #fff;
33+
text-align: center;
34+
padding: 5px;
35+
font-size: 20px;
36+
}
37+
38+
.window_body{
39+
padding: 10px;
40+
}
41+
42+
.window_closeBtn{
43+
position: absolute;
44+
right: 0;
45+
top: 0;
46+
font-size: 20px;
47+
color: #fff;
48+
background: red;
49+
cursor: pointer;
50+
padding: 5px;
51+
}
52+
53+
/*skin for window_skin_a*/
54+
.window_skin_a.window_boudingBox{
55+
box-shadow: none;
56+
border: 5px solid #ddc;
57+
border-radius: 5px;
58+
}
59+
60+
.window_skin_a .window_alertBtn{
61+
width: 50px;
62+
left: auto;
63+
right: 20px;
64+
margin-left: 0;
65+
background:red;
66+
border: none;
67+
color: #fff;
68+
padding: 10px;
69+
}
70+
71+
.window_skin_a .window_header{
72+
background: red;
73+
text-align: left;
74+
padding: 10px;
75+
font-weight: bold;
76+
}
77+
78+
.window_skin_a .window_closeBtn{
79+
width: 45px;
80+
height: 45px;
81+
border-radius: 45px;
82+
line-height: 45px;
83+
padding: 0;
84+
text-align: center;
85+
background: blue;
86+
font-size: 24px;
87+
font-weight: bold;
88+
right: -15px;
89+
top: -15px;
90+
}

8.1 定制皮肤/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>定制皮肤</title>
6+
<link type="text/css" rel="stylesheet" href="css/base.css">
7+
<link type="text/css" rel="stylesheet" href="css/window.css">
8+
</head>
9+
10+
<body>
11+
<a href="#" class="btn">弹窗</a>
12+
<script type="text/javascript" data-main="js/main" src="js/require.js"></script>
13+
</body>
14+
</html>

8.1 定制皮肤/js/jquery-2.1.1.min.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

8.1 定制皮肤/js/main.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require.config({
2+
paths:{
3+
jquery:'jquery-2.1.1.min'
4+
}
5+
});
6+
7+
require(['jquery','window'],function($,w){
8+
$('.btn').click(function(){
9+
new w.Window().alert({
10+
title:'提示',
11+
content:'Welcome!!!',
12+
handler:function(){
13+
alert('you click the button');
14+
},
15+
width:300,
16+
height:150,
17+
y:250,
18+
x:600,
19+
hasCloseBtn:true,
20+
skinClassName:'window_skin_a',
21+
handler4AlertBtn:function(){
22+
alert('你点击了确定按钮');
23+
},
24+
handler4CloseBtn:function(){
25+
alert('你点击了关闭按钮');
26+
}
27+
});
28+
});
29+
});

8.1 定制皮肤/js/require.js

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

8.1 定制皮肤/js/window.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
define(['jquery'],function($){
2+
function Window(){
3+
this.cfg = {
4+
width:500,
5+
height:300,
6+
title:'系统消息',
7+
content:"",
8+
hasCloseBtn:false,
9+
skinClassName:null,
10+
handler4AlertBtn:null,
11+
handler4CloseBtn:null
12+
};
13+
}
14+
15+
Window.prototype = {
16+
alert:function(cfg){
17+
var CFG = $.extend(this.cfg,cfg),
18+
boudingBox = $(
19+
'<div class="window_boundingBox">'+
20+
'<div class="window_header">'+CFG.title+'</div>'+
21+
'<div class="window_body">'+CFG.content+'</div>'+
22+
'<div class="window_footer"><input type="button" class="window_alertBtn" value="确定"></div>'+
23+
'</div>'
24+
),
25+
btn = boudingBox.find('.window_alertBtn');
26+
boudingBox.appendTo('body');
27+
btn.click(function(){
28+
CFG.handler4AlertBtn && CFG.handler4AlertBtn(); //弹出窗口的确定按钮处理函数
29+
boudingBox.remove();
30+
});
31+
$.extend(this.cfg,cfg);
32+
boudingBox.css({
33+
width:CFG.width+'px',
34+
height:CFG.height+'px',
35+
left:(CFG.x||(window.innerWidth-CFG.width)/2)+'px',
36+
top:(CFG.y||(window.innerHeight-CFG.height)/2)+'px'
37+
});
38+
if(CFG.hasCloseBtn){
39+
var closeBtn = $('<span class="window_closeBtn">X</span>');
40+
closeBtn.appendTo(boudingBox);
41+
closeBtn.click(function(){
42+
CFG.handler4CloseBtn&&CFG.handler4CloseBtn(); //弹出窗口的关闭按钮处理函数
43+
boudingBox.remove();
44+
});
45+
}
46+
if (CFG.skinClassName) {
47+
boudingBox.addClass(CFG.skinClassName);
48+
};
49+
50+
},
51+
confirm:function(){},
52+
prompt:function(){}
53+
}
54+
55+
return{
56+
Window : Window
57+
}
58+
})

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
* 5.1 调整接口格式
1010
* 6.1 定制标题
1111
* 7.1 定制关闭按钮
12+
* 8.1 定制皮肤

0 commit comments

Comments
 (0)