Skip to content

Commit 87068a9

Browse files
committed
toast组件支持自定义显示时间和自定义样式
1 parent 6d05b64 commit 87068a9

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

docs/_includes/_components/modal.html

+11-2
Original file line numberDiff line numberDiff line change
@@ -771,11 +771,20 @@ <h1 class="title">指示器(indicator)</h1>
771771

772772
<article class="component active" id='toast' data-url='toast'>
773773
<h2 class="component-title">toast</h2>
774-
<p class="component-description">toast是一种轻量的提示,在页面中间显示,并且会在2秒之后自动消失</p>
774+
<p class="component-description">toast是一种轻量的提示,在页面中间显示,并且会在2秒(默认值,可修改)之后自动消失</p>
775775
<p>可以用来显示一些不会打断用户操作的提示。</p>
776776

777+
{% highlight html%}
778+
/* msg{string}: toast内容
779+
* duration{number}:toast显示时间,默认2000
780+
* extraclass{string}:给toast根节点附加class,高度自定义属性,方便用户自行控制不同场景的样式。
781+
* 如果使用了第三个参数,请自行在业务css里添加extraclass对应的样式
782+
* /
783+
{% endhighlight %}
777784
{% highlight js %}
778785
$.toast("操作失败");
786+
787+
$.toast('操作成功,正在跳转...', 2345, 'success top');
788+
779789
{% endhighlight %}
780-
<p>toast 组件后续会支持不同的情景,包括操作成功、操作失败等,显示出不同的颜色</p>
781790
</article>

js/fastclick.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@
220220

221221
/**
222222
* 判断是否组合型label
223-
* 夏苒添加
224-
*
225223
* @type {Boolean}
226224
*/
227225
var isCompositeLabel = false;
@@ -234,16 +232,8 @@
234232
*/
235233
FastClick.prototype.needsClick = function(target) {
236234

237-
// 修复bug: 如果父元素中有 label
238-
// 夏苒删除
239-
/*
240-
var parent = target;
241-
while(parent && (parent.tagName.toUpperCase() !== "BODY")) {
242-
if(parent.tagName.toUpperCase() === "LABEL") return true;
243-
parent = parent.parentNode;
244-
}
245-
*/
246-
// 夏苒添加start,如果label上有needsclick这个类,则用原生的点击,否则,用模拟点击
235+
// 修复bug: 如果父元素中有 label
236+
// 夏苒添加start,如果label上有needsclick这个类,则用原生的点击,否则,用模拟点击
247237
var parent = target;
248238
while(parent && (parent.tagName.toUpperCase() !== "BODY")) {
249239
if (parent.tagName.toUpperCase() === "LABEL") {
@@ -687,7 +677,6 @@
687677

688678
// Cancel the event
689679
event.stopPropagation();
690-
// event.preventDefault(); 夏苒删除
691680
// 允许组合型label冒泡,夏苒添加start
692681
if (!isCompositeLabel) {
693682
event.preventDefault();

js/modal.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,12 @@
268268
return modal[0];
269269
};
270270
//显示一个消息,会在2秒钟后自动消失
271-
$.toast = function(msg) {
272-
var $toast = $("<div class='modal toast'>"+msg+"</div>").appendTo(document.body);
271+
$.toast = function(msg, duration, extraclass) {
272+
var $toast = $('<div class="modal toast ' + (extraclass || '') + '">' + msg + '</div>').appendTo(document.body);
273273
$.openModal($toast);
274274
setTimeout(function() {
275275
$.closeModal($toast);
276-
}, 2000);
276+
}, duration || 2000);
277277
};
278278
$.openModal = function (modal) {
279279
modal = $(modal);

0 commit comments

Comments
 (0)