|
44 | 44 | </head> |
45 | 45 | <body> |
46 | 46 | <header>Tip</header> |
47 | | - <div class="container"> |
| 47 | + <div id="container" class="container" style="margin-left:100px"> |
48 | 48 | <div data-ui="type:Tip;id:tip;title:写这里优先级高;content:我是内容;arrow:1" title="也可以写在这里">content也可以写在这里</div> |
49 | | - <esui-tip data-ui="type:Tip;id:tip;title:写这里优先级高;content:我是内容;arrow:1" title="也可以写在这里"></esui-tip> |
50 | 49 |
|
51 | 50 | <br> |
52 | 51 | <label id="tip-layer-label"> |
|
57 | 56 | <br> |
58 | 57 | <br> |
59 | 58 | <Button data-ui-id="control-tip" data-ui-type="Button"> |
60 | | - 可以帮在控件上 |
| 59 | + 划过展示弹层 |
61 | 60 | </Button> |
62 | 61 | <br> |
63 | 62 | <br> |
64 | 63 | <Button data-ui-id="control-tip-2" data-ui-type="Button"> |
65 | | - 我跟楼上的共享一个tip |
| 64 | + 点击展示弹层 |
| 65 | + </Button> |
| 66 | + <br> |
| 67 | + <br> |
| 68 | + <Button data-ui-id="control-tip-3" data-ui-type="Button"> |
| 69 | + 自动展示弹层 |
| 70 | + </Button> |
| 71 | + <br> |
| 72 | + <br> |
| 73 | + <Button data-ui-id="control-tip-4" data-ui-type="Button"> |
| 74 | + 定制展示弹层 |
| 75 | + </Button> |
| 76 | + <br> |
| 77 | + <br> |
| 78 | + <p>TipLayer支持多个元素共享,但不适用showMode为auto的绑定</p> |
| 79 | + <Button data-ui-id="control-tip-3-1" data-ui-type="Button"> |
| 80 | + 我们跟第三个按钮共享一个tip |
66 | 81 | </Button> |
67 | 82 | </div> |
68 | 83 | <script> |
|
75 | 90 | ], |
76 | 91 | function (ui, Tip, TipLayer) { |
77 | 92 | var controls = ui.init(); |
78 | | - var tip = controls[0]; |
79 | | - |
80 | | - var onceNotice = TipLayer.onceNotice({ |
81 | | - content: '你知道了吗知道了吗知道了吗?', |
82 | | - targetDOM: 'tip-layer-label' |
| 93 | + /** |
| 94 | + * 场景1:over |
| 95 | + */ |
| 96 | + var tipLayer1 = ui.create('TipLayer', { |
| 97 | + title: 'over模式弹层', |
| 98 | + content: 'over模式下的交互是:<br>' |
| 99 | + + '鼠标划过目标元素,弹层出现;鼠标脱离目标元素弹层消失' |
83 | 100 | }); |
| 101 | + tipLayer1.appendTo(document.body) |
| 102 | + tipLayer1.render(); |
84 | 103 |
|
85 | | - var tipLayer = ui.create('TipLayer', { |
86 | | - title: '最普通的提示', |
87 | | - content: '随便提示一下随便提示一下随便提示一下' |
88 | | - }); |
89 | | - tipLayer.appendTo(document.body) |
90 | | - tipLayer.render(); |
91 | | - tipLayer.attachTo({ |
| 104 | + tipLayer1.attachTo({ |
92 | 105 | targetControl: 'control-tip', |
93 | 106 | showMode: 'over', |
94 | 107 | delayTime: 800, |
95 | | - positionOpt: { top: 'top', right: 'left' } |
| 108 | + positionOpt: {top: 'top', right: 'left'} |
96 | 109 | }); |
97 | 110 |
|
98 | | - tipLayer.attachTo({ |
| 111 | + |
| 112 | + /** |
| 113 | + * 场景2:click |
| 114 | + */ |
| 115 | + var tipLayer2 = ui.create('TipLayer', { |
| 116 | + title: 'click模式弹层', |
| 117 | + content: 'click模式下的交互是:<br>' |
| 118 | + + '点击目标元素,弹层出现;点击layer及目标元素以外区域,弹层消失' |
| 119 | + }); |
| 120 | + tipLayer2.appendTo(document.body) |
| 121 | + tipLayer2.render(); |
| 122 | + |
| 123 | + tipLayer2.attachTo({ |
99 | 124 | targetControl: 'control-tip-2', |
100 | 125 | showMode: 'click', |
101 | 126 | delayTime: 300, |
102 | 127 | positionOpt: { top: 'top', right: 'left' } |
103 | | - }) |
| 128 | + }); |
| 129 | + |
| 130 | + |
| 131 | + /** |
| 132 | + * 场景3:auto |
| 133 | + */ |
| 134 | + var tipLayer3 = ui.create('TipLayer', { |
| 135 | + title: 'auto模式弹层', |
| 136 | + content: 'auto模式下的交互是:<br>' |
| 137 | + + '弹层自动出现;并根据用户配置的showDuration决定:<br>' |
| 138 | + + '1. 经过showDuration的时间后自动关闭<br>' |
| 139 | + + '2. 点击外部执行关闭 ' |
| 140 | + + '之后,点击目标元素,展示弹层' |
| 141 | + }); |
| 142 | + tipLayer3.appendTo(document.body) |
| 143 | + tipLayer3.render(); |
| 144 | + |
| 145 | + tipLayer3.attachTo({ |
| 146 | + targetControl: 'control-tip-3', |
| 147 | + showMode: 'over', |
| 148 | + // showDuration: 3600, |
| 149 | + positionOpt: {top: 'top', right: 'left'} |
| 150 | + }); |
| 151 | + |
| 152 | + /** |
| 153 | + * 场景4:把一个已经生成的TipLayer共享给另一个元素 |
| 154 | + */ |
| 155 | + tipLayer3.attachTo({ |
| 156 | + targetControl: 'control-tip-3-1', |
| 157 | + showMode: 'over', |
| 158 | + positionOpt: {top: 'top', right: 'left'} |
| 159 | + }); |
| 160 | + |
| 161 | + // 共享给好多好多元素 |
| 162 | + var container = document.getElementById('container'); |
| 163 | + var i = 20; |
| 164 | + while (i > 0) { |
| 165 | + var dom = document.createElement('div'); |
| 166 | + dom.id = i; |
| 167 | + dom.setAttribute('class', 'ui-button'); |
| 168 | + container.appendChild(dom); |
| 169 | + tipLayer3.attachTo({ |
| 170 | + targetDOM: dom, |
| 171 | + showMode: 'over', |
| 172 | + delayTime: 800, |
| 173 | + positionOpt: {top: 'top', right: 'left'} |
| 174 | + }); |
| 175 | + i--; |
| 176 | + } |
| 177 | + |
| 178 | + /** |
| 179 | + * 场景4:manual |
| 180 | + */ |
| 181 | + var tipLayer4 = ui.create('TipLayer', { |
| 182 | + title: 'manual模式弹层', |
| 183 | + content: 'manual模式下的交互是:随你自己搞' |
| 184 | + }); |
| 185 | + tipLayer4.appendTo(document.body) |
| 186 | + tipLayer4.render(); |
| 187 | + |
| 188 | + ui.get('control-tip-4').on( |
| 189 | + 'click', |
| 190 | + function () { |
| 191 | + tipLayer4.show(this.main, {top: 'top', right: 'left'}); |
| 192 | + } |
| 193 | + ); |
| 194 | + |
| 195 | + tipLayer4.helper.addDOMEvent( |
| 196 | + ui.get('control-tip-4').main, |
| 197 | + 'mouseout', |
| 198 | + function () { |
| 199 | + this.hide(); |
| 200 | + } |
| 201 | + ); |
| 202 | + |
| 203 | + var tip = controls[0]; |
| 204 | + |
| 205 | + |
| 206 | + var onceNotice = TipLayer.onceNotice({ |
| 207 | + content: '你知道了吗知道了吗知道了吗?', |
| 208 | + targetDOM: 'tip-layer-label' |
| 209 | + }); |
104 | 210 | } |
105 | 211 | ) |
106 | 212 | </script> |
|
0 commit comments