Skip to content

Commit e480ded

Browse files
committedMay 23, 2017
notification
1 parent 934d956 commit e480ded

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
 

‎jquery.notification.js

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
(function($) {
2+
var obj = {
3+
icon: '',
4+
title: '提示',
5+
desc: ''
6+
};
7+
jQuery.fn.extend({
8+
notificationShow: function(){
9+
this.show();
10+
},
11+
notificationHide: function(){
12+
this.hide();
13+
this.empty();
14+
},
15+
notification : function(o) {
16+
o = $.extend(obj,o);
17+
if(this) {
18+
var group = '<div class="notification_group"><h2 class="notification_title">'+ o.title +'</h2>'+
19+
'<div class="desc">'+ o.desc +'</div></div>';
20+
var close = '<div class="notification_close" style="position:absolute;top:10px;right:10px;color:#bfcbd9;line-height:1;cursor:pointer;"><i class="iconfont" style="font-size:24px;">&#xe600;</i></div>';
21+
var icon = '';
22+
if(o.icon) {
23+
if(o.icon === 'success')
24+
icon = '<div class="icon_wrap"><i class="iconfont" style="color:#13ce66;">&#xe642;</i></div>';
25+
else if(o.icon === 'warning')
26+
icon = '<div class="icon_wrap"><i class="iconfont" style="color:#f7ba2a;">&#xe6d4;</i></div>';
27+
else if(o.icon === 'error')
28+
icon = '<div class="icon_wrap"><i class="iconfont" style="color:#ff4949;">&#xe641;</i></div>';
29+
}
30+
31+
// 样式
32+
this.css({
33+
//'display': 'none',
34+
'position': 'fixed',
35+
'right': '16px',
36+
'bottom': '50px',
37+
'padding': '20px',
38+
'z-index': '1002',
39+
'width': '330px',
40+
'boxSize': 'border-box',
41+
'borderRadius': '2px',
42+
'backgroundColor': '#fff',
43+
'boxShadow': '0 2px 4px rgba(0,0,0,.12),0 0 6px rgba(0,0,0,.04)',
44+
'transition': 'all .3s',
45+
'overflow': 'hidden'
46+
});
47+
48+
this.addClass('clear');
49+
this.empty().append(icon+group+close);
50+
var _this = this;
51+
52+
// 自动消失
53+
setTimeout(function(){
54+
_this.notificationHide();
55+
},2500);
56+
57+
// 手动关闭
58+
$('.notification_close').click(function(){
59+
_this.notificationHide();
60+
});
61+
62+
$('.icon_wrap').css({
63+
'float': 'left',
64+
'lineHeight': 1,
65+
'position': 'relative',
66+
'top': '5px'
67+
});
68+
69+
$('.icon_wrap .iconfont').css({
70+
'font-size': '40px',
71+
72+
});
73+
74+
$('.notification_group').css({
75+
'marginLeft': '50px'
76+
});
77+
78+
$('.notification_group .notification_title').css({
79+
'margin': '0',
80+
'fontSize' : '18px',
81+
'color': '#000'
82+
});
83+
$('.notification_group .desc').css({
84+
'margin': '0',
85+
'color' : '#8391a5'
86+
});
87+
}
88+
}
89+
});
90+
})(jQuery);

0 commit comments

Comments
 (0)