修改my-message jquery 消息插件
来源:互联网 发布:火车头采集本地数据 编辑:程序博客网 时间:2024/05/21 08:36
对jQuery my-message 的效果不是很满意,修改了一下:
http://www.menucool.com/tooltip/javascript-tooltip :也是一款不错的弹出框插件
JavaScript Code
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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<title></title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<link rel="stylesheet" href="css/jquery.my-message.1.1.css" />
</head>
<body>
<button id="btn1">普通的</button>
<button id="btn2">成功的</button>
<button id="btn3">警告的</button>
<button id="btn4">错误的</button>
<script type="text/javascript" src="js/jquery1.9.min.js"></script>
<script type="text/javascript" src="js/jquery.my-message.1.1.js"></script>
<script>
var message = new MyMessage.message({
/*默认参数,下面为默认项*/
iconFontSize: "20px", //图标大小,默认为20px
messageFontSize: "12px", //信息字体大小,默认为12px
showTime: 10, //消失时间,默认为3000
align: "center", //显示的位置类型center,right,left
positions: { //放置信息距离周边的距离,默认为10px
top: "10px",
bottom: "10px",
right: "10px",
left: "10px"
},
message: "这是一条消息", //消息内容,默认为"这是一条消息"
type: "normal", //消息的类型,还有success,error,warning等,默认为normal
});
/*两种不同的设置方式*/
message.setting({
align: "center" //会覆盖前面的所有设置,可以创建不同的对象去避免覆盖
});
message.setting("showTime", "1000");
$('#btn1').click(function() {
message.add("普通的消息");
});
$('#btn2').click(function() {
message.add("成功的消息", "success");
});
$('#btn3').click(function() {
message.add("警告的消息", "warning");
});
$('#btn4').click(function() {
message.add("错误的消息", "error");
});
</script>
</body>
</html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<title></title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<link rel="stylesheet" href="css/jquery.my-message.1.1.css" />
</head>
<body>
<button id="btn1">普通的</button>
<button id="btn2">成功的</button>
<button id="btn3">警告的</button>
<button id="btn4">错误的</button>
<script type="text/javascript" src="js/jquery1.9.min.js"></script>
<script type="text/javascript" src="js/jquery.my-message.1.1.js"></script>
<script>
var message = new MyMessage.message({
/*默认参数,下面为默认项*/
iconFontSize: "20px", //图标大小,默认为20px
messageFontSize: "12px", //信息字体大小,默认为12px
showTime: 10, //消失时间,默认为3000
align: "center", //显示的位置类型center,right,left
positions: { //放置信息距离周边的距离,默认为10px
top: "10px",
bottom: "10px",
right: "10px",
left: "10px"
},
message: "这是一条消息", //消息内容,默认为"这是一条消息"
type: "normal", //消息的类型,还有success,error,warning等,默认为normal
});
/*两种不同的设置方式*/
message.setting({
align: "center" //会覆盖前面的所有设置,可以创建不同的对象去避免覆盖
});
message.setting("showTime", "1000");
$('#btn1').click(function() {
message.add("普通的消息");
});
$('#btn2').click(function() {
message.add("成功的消息", "success");
});
$('#btn3').click(function() {
message.add("警告的消息", "warning");
});
$('#btn4').click(function() {
message.add("错误的消息", "error");
});
</script>
</body>
</html>
修改的插件:72~74行
JavaScript Code
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* 支持浏览器:IE8+
* */
var MyMessage = (function() {
function message(setting) {
//合并默认参数
this.messageContainer = null;
this.opts = null;
this.$domStr=null;//新加的对象
this._setting(setting);
this.init();
}
/*默认参数*/
message.DEFAULTS = {
iconFontSize: "20px", //图标大小
messageFontSize: "12px", //信息字体大小
showTime: 3000, //消失时间
align: "center", //显示的位置
positions: { //放置信息的范围
top: "10px",
bottom: "10px",
right: "10px",
left: "10px"
},
message: "这是一条消息", //消息内容
type: "normal", //消息的类型,还有success,error,warning等
}
/*设置消息的参数*/
message.prototype._setting = function(setting) {
this.opts = $.extend({}, message.DEFAULTS, setting);
}
message.prototype.setting = function(key, val) {
console.log(arguments.length);
if(arguments.length === 1) {
if("object" === typeof key) {
for(var k in key) {
this.opts[k] = key[k]
}
}
} else if(arguments.length === 2) {
if("string" === typeof key) {
this.opts[key] = val;
}
}
}
/*
用于添加相应的dom到body标签中
* */
message.prototype.init = function() {
var domStr = "<div class='m-message' style='top:" +
this.opts.positions.top +
";right:" +
this.opts.positions.right +
";left:" +
this.opts.positions.left +
";width:calc(100%-" +
this.opts.positions.right +
this.opts.positions.left +
");bottom:" + this.opts.positions.bottom +
"'></div>"
this.messageContainer = $(domStr);
this.messageContainer.appendTo($('body'))
}
/*
用于添加消息到相应的标签中
message:具体的消息
type:消息的类型
* */
message.prototype.add = function(message, type) {
//判断如果之前有dom就隐藏,如果没有就生成,页面始终就会只会有一个消息弹窗口,可能是需求不一样,如果要多个就可以注释这个代码
if(null != this.$domStr){
this._hideImmediately(this.$domStr);
}
var domStr = "";
type = type || this.opts.type;
domStr += "<div class='c-message-notice' style='" +
"text-align:" +
this.opts.align +
";'><div class='m_content'><i class='";
switch(type) {
case "normal":
domStr += "icon-bubble";
break;
case "success":
domStr += "icon-check-alt";
break;
case "error":
domStr += "icon-notification";
break;
case "warning":
domStr += "icon-cancel-circle";
break;
default:
throw "传递的参数type错误,请传递normal/success/error/warning中的一种";
break;
}
domStr += "' style='font-size:" +
this.opts.iconFontSize +
";'></i><span style='font-size:" +
this.opts.messageFontSize +
";'>" + message + "</span></div></div>";
this.$domStr = $(domStr).appendTo(this.messageContainer);
this._hide(this.$domStr);
}
/**
* 隐藏消息
* $domStr:该消息的jq对象
* */
message.prototype._hide = function($domStr) {
setTimeout(function() {
$domStr.fadeOut(1000);
}, this.opts.showTime);
}
//新添加的方法
message.prototype._hideImmediately = function($domStr) {
$domStr.hide();
}
return {
message: message /*对外提供的接口*/
}
})();
* 支持浏览器:IE8+
* */
var MyMessage = (function() {
function message(setting) {
//合并默认参数
this.messageContainer = null;
this.opts = null;
this.$domStr=null;//新加的对象
this._setting(setting);
this.init();
}
/*默认参数*/
message.DEFAULTS = {
iconFontSize: "20px", //图标大小
messageFontSize: "12px", //信息字体大小
showTime: 3000, //消失时间
align: "center", //显示的位置
positions: { //放置信息的范围
top: "10px",
bottom: "10px",
right: "10px",
left: "10px"
},
message: "这是一条消息", //消息内容
type: "normal", //消息的类型,还有success,error,warning等
}
/*设置消息的参数*/
message.prototype._setting = function(setting) {
this.opts = $.extend({}, message.DEFAULTS, setting);
}
message.prototype.setting = function(key, val) {
console.log(arguments.length);
if(arguments.length === 1) {
if("object" === typeof key) {
for(var k in key) {
this.opts[k] = key[k]
}
}
} else if(arguments.length === 2) {
if("string" === typeof key) {
this.opts[key] = val;
}
}
}
/*
用于添加相应的dom到body标签中
* */
message.prototype.init = function() {
var domStr = "<div class='m-message' style='top:" +
this.opts.positions.top +
";right:" +
this.opts.positions.right +
";left:" +
this.opts.positions.left +
";width:calc(100%-" +
this.opts.positions.right +
this.opts.positions.left +
");bottom:" + this.opts.positions.bottom +
"'></div>"
this.messageContainer = $(domStr);
this.messageContainer.appendTo($('body'))
}
/*
用于添加消息到相应的标签中
message:具体的消息
type:消息的类型
* */
message.prototype.add = function(message, type) {
//判断如果之前有dom就隐藏,如果没有就生成,页面始终就会只会有一个消息弹窗口,可能是需求不一样,如果要多个就可以注释这个代码
if(null != this.$domStr){
this._hideImmediately(this.$domStr);
}
var domStr = "";
type = type || this.opts.type;
domStr += "<div class='c-message-notice' style='" +
"text-align:" +
this.opts.align +
";'><div class='m_content'><i class='";
switch(type) {
case "normal":
domStr += "icon-bubble";
break;
case "success":
domStr += "icon-check-alt";
break;
case "error":
domStr += "icon-notification";
break;
case "warning":
domStr += "icon-cancel-circle";
break;
default:
throw "传递的参数type错误,请传递normal/success/error/warning中的一种";
break;
}
domStr += "' style='font-size:" +
this.opts.iconFontSize +
";'></i><span style='font-size:" +
this.opts.messageFontSize +
";'>" + message + "</span></div></div>";
this.$domStr = $(domStr).appendTo(this.messageContainer);
this._hide(this.$domStr);
}
/**
* 隐藏消息
* $domStr:该消息的jq对象
* */
message.prototype._hide = function($domStr) {
setTimeout(function() {
$domStr.fadeOut(1000);
}, this.opts.showTime);
}
//新添加的方法
message.prototype._hideImmediately = function($domStr) {
$domStr.hide();
}
return {
message: message /*对外提供的接口*/
}
})();
阅读全文
0 0
- 修改my-message jquery 消息插件
- 使用jQuery的message插件实现右下角弹出消息框
- 使用jQuery的message插件实现右下角弹出消息框
- 使用jQuery的message插件实现右下角弹出消息框
- 使用jQuery的message插件实现右下角弹出消息框
- JQuery HashChange插件修改
- JQuery HashChange插件修改
- jquery的一个消息插件
- jquery插件封装:消息对话框
- Jquery消息提示插件toastr
- jQuery Growl 消息提醒插件
- jquery插件jquery.confirm弹出确认消息
- My Message 1.6 Published
- 基于jquery的消息通知插件
- 一款小巧的jquery消息提示插件
- toastr jQuery消息通知插件文档
- jQuery消息提示框插件Tipso
- JQuery 25 个超棒的消息提醒插件
- 【Linux】Linux一些需要掌握的命令和内容
- 深度学习利器: TensorFlow系统架构及高性能程序设计
- httpd(apache)服务器--知识总结(2)
- 关于死锁
- Hibernate延迟加载(查询优化),关联级别延迟加载优化策略
- 修改my-message jquery 消息插件
- 人工智能的发展
- PAT乙级 1016. 部分A+B (15)
- 第一章 Web MVC简介 —— 跟开涛学SpringMVC 博客分类: 跟开涛学SpringMVC webmvcjavaeespring跟开涛学SpringMVC Web MVC简介 1.1、We
- Math对象
- 2序列比对问题
- Numpy-基本操作
- PAT乙级 1017. A除以B (20)
- gopl-Exercise1.7-9: Fetch