Showing
6 changed files
with
78 additions
and
1 deletions
@@ -109,6 +109,8 @@ iconfont 新建项目,使用 class 控制图标样式,不要用 unicode<br> | @@ -109,6 +109,8 @@ iconfont 新建项目,使用 class 控制图标样式,不要用 unicode<br> | ||
109 | <h2>tip</h2> | 109 | <h2>tip</h2> |
110 | 可以控制显示,隐藏 | 110 | 可以控制显示,隐藏 |
111 | 支持设置,自动消失 | 111 | 支持设置,自动消失 |
112 | +<br> | ||
113 | +<button id="show-tip" class="button button-small" type="button">click 显示tip</button> | ||
112 | 114 | ||
113 | <h2>loading</h2> | 115 | <h2>loading</h2> |
114 | 可以控制显示,隐藏 | 116 | 可以控制显示,隐藏 |
public/hbs/components/tip.hbs
0 → 100644
1 | +<div class="tip">{{txt}}</div> |
public/js/common/tip.js
0 → 100644
1 | +/** | ||
2 | + * tip | ||
3 | + * @author chenxuan <xuan.chen@yoho.cn> | ||
4 | + * | ||
5 | + * @example | ||
6 | + * tip('lalalalal~') | ||
7 | + * | ||
8 | + * @example | ||
9 | + * tip({ | ||
10 | + * txt: 'lalalalal', | ||
11 | + * delay: 2000 | ||
12 | + * }) | ||
13 | + */ | ||
14 | + | ||
15 | +function tip(param) { | ||
16 | + let timer; | ||
17 | + const viewData = { | ||
18 | + mask: false, | ||
19 | + delay: 2000, | ||
20 | + txt: '' | ||
21 | + }; | ||
22 | + | ||
23 | + if (typeof param === 'string') { | ||
24 | + $.extend(viewData, { txt: param }); | ||
25 | + } else { | ||
26 | + $.extend(viewData, param); | ||
27 | + } | ||
28 | + | ||
29 | + const tipView = `<div class="tip-box"><div class="tip">${viewData.txt}</div></div>`; | ||
30 | + const $oldTip = $('.tip'); | ||
31 | + | ||
32 | + if ($oldTip.length) { | ||
33 | + timer = $oldTip.data('timer'); | ||
34 | + clearTimeout(timer); | ||
35 | + $oldTip.remove(); | ||
36 | + } | ||
37 | + | ||
38 | + const $tip = $(tipView).appendTo(document.body); | ||
39 | + | ||
40 | + $tip.data('timer', setTimeout(function() { | ||
41 | + $tip.remove(); | ||
42 | + }, viewData.delay)); | ||
43 | +} | ||
44 | + | ||
45 | +module.exports = tip; |
@@ -2,6 +2,7 @@ var Vue = require('yoho-vue'); | @@ -2,6 +2,7 @@ var Vue = require('yoho-vue'); | ||
2 | 2 | ||
3 | var app = require('example/home.vue'); | 3 | var app = require('example/home.vue'); |
4 | var tpl = require('example/hello.hbs'); | 4 | var tpl = require('example/hello.hbs'); |
5 | +var tip = require('../common/tip'); | ||
5 | 6 | ||
6 | var vm = new Vue({ | 7 | var vm = new Vue({ |
7 | el: '#app', | 8 | el: '#app', |
@@ -39,5 +40,11 @@ $('#hbs-placeholder').html(tpl({ | @@ -39,5 +40,11 @@ $('#hbs-placeholder').html(tpl({ | ||
39 | text: 'Handlerbars' | 40 | text: 'Handlerbars' |
40 | })); | 41 | })); |
41 | 42 | ||
43 | +/* --------------tip demo---------*/ | ||
44 | +var tipBtn = document.querySelector('#show-tip'); | ||
45 | +tipBtn.addEventListener('click', function(){ | ||
46 | + tip('中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中') | ||
47 | +}) | ||
48 | + | ||
42 | 49 | ||
43 | /* eslint-enable */ | 50 | /* eslint-enable */ |
1 | +.tip-box { | ||
2 | + position: fixed; | ||
3 | + top: 50%; | ||
4 | + left: 50%; | ||
5 | + z-index: 998; | ||
6 | + transform: translate(-50%, -50%); | ||
7 | + display: table; | ||
8 | + max-width: 90%; | ||
9 | + min-height: 100px; | ||
10 | + border-radius: 8px; | ||
11 | + text-align: center; | ||
12 | + font-size: 28px; | ||
13 | + color: #fff; | ||
14 | + background-color: rgba(0, 0, 0, 0.7); | ||
15 | + padding: 10px 20px; | ||
16 | + | ||
17 | + .tip { | ||
18 | + display: table-cell; | ||
19 | + vertical-align: middle; | ||
20 | + } | ||
21 | +} | ||
22 | + |
-
Please register or login to post a comment