tencent.jquery.pix.component 1.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/banner/banner.js +450 -0
- package/components/banner/banner.scss +46 -0
- package/components/config.js +23 -0
- package/components/list/list.js +212 -0
- package/components/tips/tipv2.js +557 -0
- package/components/utils/env.js +7 -0
- package/components/utils/utils.js +65 -0
- package/components/video/resources/images/control-bg.png +0 -0
- package/components/video/resources/images/exit-full-screen.png +0 -0
- package/components/video/resources/images/full-screen.png +0 -0
- package/components/video/resources/images/mute.png +0 -0
- package/components/video/resources/images/origin-play.png +0 -0
- package/components/video/resources/images/pause.png +0 -0
- package/components/video/resources/images/play.png +0 -0
- package/components/video/resources/images/replay.png +0 -0
- package/components/video/resources/images/volume.png +0 -0
- package/components/video/videocss.scss +497 -0
- package/components/video/videohtml.js +85 -0
- package/components/video/videoplayer.js +355 -0
- package/components/waterfall/waterfall.js +393 -0
- package/index.js +10 -0
- package/package.json +16 -0
- package/readme.md +15 -0
- package/utils/utils.js +16 -0
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tips组件
|
|
3
|
+
* - 会增加设置body的click事件
|
|
4
|
+
*/
|
|
5
|
+
import { $, windowEnv } from "../config";
|
|
6
|
+
import { addResizeFunc, removeResizeFunc, addScrollFunc, removeScrollFunc } from '../utils/utils'
|
|
7
|
+
|
|
8
|
+
// 记录是否在body上有过绑定
|
|
9
|
+
let hasBind = false
|
|
10
|
+
// x轴偏移量
|
|
11
|
+
const baseSpaceX = 4
|
|
12
|
+
// y轴偏移量
|
|
13
|
+
const baseSpaceY = -12
|
|
14
|
+
// 已实例的tips对象数组
|
|
15
|
+
const tipsArr = []
|
|
16
|
+
// 临时性的tips对象数组 - 针对showTips
|
|
17
|
+
let tmpTipsArr = []
|
|
18
|
+
// 被主动remove的tips对象数组
|
|
19
|
+
let tmp2TipsArr = []
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 实例化绑定某个元素,生成tips
|
|
23
|
+
* options
|
|
24
|
+
* {
|
|
25
|
+
* - baseDom 基准元素/位置参照物
|
|
26
|
+
* - tipElem 要tips的元素/字符串
|
|
27
|
+
* - dir 方向位置:left,right
|
|
28
|
+
* - position {x,y} 偏移量 距离基础元素的距离
|
|
29
|
+
* - clearOther 打开tip时,是否默认关掉其他的tip 默认值true
|
|
30
|
+
* - event {
|
|
31
|
+
* openClick 是否开启click绑定事件 默认为true
|
|
32
|
+
* click 按钮点击时的回调函数
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* @date 2024-11-07
|
|
36
|
+
* @param { * } options
|
|
37
|
+
*/
|
|
38
|
+
export const tips = (options) => {
|
|
39
|
+
if (hasBind === false) {
|
|
40
|
+
hasBind = true
|
|
41
|
+
initEvent()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const tipObj = new tip(options)
|
|
45
|
+
tipsArr.push(tipObj)
|
|
46
|
+
return tipObj
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 展示tips,临时性的。 如果body点击,则销毁整块内容
|
|
51
|
+
* @param {*} options
|
|
52
|
+
*/
|
|
53
|
+
export const showTips = (options) => {
|
|
54
|
+
if (hasBind === false) {
|
|
55
|
+
hasBind = true
|
|
56
|
+
initEvent()
|
|
57
|
+
}
|
|
58
|
+
let tipObj = null
|
|
59
|
+
// 首先获取已有的tip,根据baseDom
|
|
60
|
+
const alreadyTip = getAlreadyTip(options.baseDom)
|
|
61
|
+
if (alreadyTip) {
|
|
62
|
+
tipObj = alreadyTip
|
|
63
|
+
tipObj.show();
|
|
64
|
+
} else {
|
|
65
|
+
tipObj = new tip(options, true)
|
|
66
|
+
tmpTipsArr.push(tipObj)
|
|
67
|
+
tipObj.show(false);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return tipObj
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 初始化/新增一个新的tips容器元素
|
|
74
|
+
const initNewDom = (options) => {
|
|
75
|
+
if (!('position' in options)) {
|
|
76
|
+
options.position = { x: baseSpaceX, y: baseSpaceY }
|
|
77
|
+
} else {
|
|
78
|
+
options.position = Object.assign({ x: baseSpaceX, y: baseSpaceY }, options.position)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const $tipContent = $('<div class="pix-tips-container"></div>').css({
|
|
82
|
+
display: 'none',
|
|
83
|
+
position: 'fixed',
|
|
84
|
+
zIndex: '99999',
|
|
85
|
+
opacity: 0,
|
|
86
|
+
flexDirection: 'column',
|
|
87
|
+
// overflow:'scroll',
|
|
88
|
+
height: 'auto'
|
|
89
|
+
//width:'fit-content',
|
|
90
|
+
});
|
|
91
|
+
$(document.body).append($tipContent);
|
|
92
|
+
|
|
93
|
+
const $child = $(options.tipElem).css({
|
|
94
|
+
'opacity': 0
|
|
95
|
+
});
|
|
96
|
+
$(document.body).append($child)
|
|
97
|
+
|
|
98
|
+
if ($child.css('display') === 'none') {
|
|
99
|
+
$child.show();
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
$tipContent,
|
|
103
|
+
$tipChild: $child
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 初始化body点击事件,用于点击任意处关闭tips
|
|
108
|
+
const initEvent = () => {
|
|
109
|
+
$(document.body).on('click', function (e) {
|
|
110
|
+
let info = {
|
|
111
|
+
clickTip: null,
|
|
112
|
+
index: -1,
|
|
113
|
+
type: '' // 1为tips实例化重复使用的 2为showTips临时生成,如果点击到其他位置则会进行实体删除
|
|
114
|
+
}
|
|
115
|
+
for (let i = 0; i < tipsArr.length; i++) {
|
|
116
|
+
// 点击到基准元素,不做处理
|
|
117
|
+
// 如果 clearOther 为false才不做处理,为true则要关闭/隐藏其他的tip
|
|
118
|
+
if (tipsArr[i].$baseContent[0] === e.target) {
|
|
119
|
+
info = {
|
|
120
|
+
clickTip: tipsArr[i],
|
|
121
|
+
index: i,
|
|
122
|
+
type: '1'
|
|
123
|
+
}
|
|
124
|
+
break
|
|
125
|
+
}
|
|
126
|
+
// 从基准元素之内触发的事件也不做处理
|
|
127
|
+
if (tipsArr[i].$baseContent.find(e.target)[0] === e.target) {
|
|
128
|
+
info = {
|
|
129
|
+
clickTip: tipsArr[i],
|
|
130
|
+
index: i,
|
|
131
|
+
type: '1'
|
|
132
|
+
}
|
|
133
|
+
break
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// 如果 clearOther 为false才不做处理,为true则要关闭/隐藏其他的tip
|
|
137
|
+
if (info.clickTip && info.clickTip.clearOther === false) {
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
if (info.clickTip === null) {
|
|
141
|
+
for (let i = 0; i < tmpTipsArr.length; i++) {
|
|
142
|
+
const item = tmpTipsArr[i]
|
|
143
|
+
// 点击到基准元素,不做处理
|
|
144
|
+
if (isClick(item, e)) {
|
|
145
|
+
info = {
|
|
146
|
+
clickTip: item,
|
|
147
|
+
index: i,
|
|
148
|
+
type: '1'
|
|
149
|
+
}
|
|
150
|
+
break
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// 如果 clearOther 为false才不做处理,为true则要关闭/隐藏其他的tip
|
|
155
|
+
if (info.clickTip && info.clickTip.clearOther === false) {
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
for (let i = 0; i < tipsArr.length; i++) {
|
|
160
|
+
if (info.clickTip && info.clickTip === tipsArr[i]) {
|
|
161
|
+
// 如果点的是自己,那么什么都不做
|
|
162
|
+
continue
|
|
163
|
+
}
|
|
164
|
+
tipsArr[i].hide()
|
|
165
|
+
}
|
|
166
|
+
for (let i = 0; i < tmpTipsArr.length; i++) {
|
|
167
|
+
// info.clickTip && info.clickTip === tmpTipsArr[i])
|
|
168
|
+
if (isClick(tmpTipsArr[i], e)) {
|
|
169
|
+
// 如果点的是自己,那么什么都不做
|
|
170
|
+
continue
|
|
171
|
+
}
|
|
172
|
+
tmpTipsArr[i].remove()
|
|
173
|
+
tmpTipsArr.splice(i, 1)
|
|
174
|
+
i = i - 1
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
//tmpTipsArr = []
|
|
178
|
+
tmp2TipsArr = []
|
|
179
|
+
});
|
|
180
|
+
if (windowEnv === 'pix') {
|
|
181
|
+
$(document.body).on('click', '.pix-tips-container', function () {
|
|
182
|
+
// 点击到tip弹窗阻止冒泡
|
|
183
|
+
}, true)
|
|
184
|
+
} else {
|
|
185
|
+
$(document.body).on('click', '.pix-tips-container', function (e) {
|
|
186
|
+
// 点击到tip弹窗阻止冒泡
|
|
187
|
+
e.stopPropagation(); // 阻止事件冒泡
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// 考虑到其他可能存在的场景,用原型链对象形式
|
|
193
|
+
const tip = function (options, isTemp = false) {
|
|
194
|
+
this.options = options
|
|
195
|
+
if (!this.options.event) {
|
|
196
|
+
// 定义默认openClick值 能否点击隐藏/展示
|
|
197
|
+
this.options.event = { openClick: true }
|
|
198
|
+
}
|
|
199
|
+
const self = this
|
|
200
|
+
this.isTemp = isTemp
|
|
201
|
+
const info = initNewDom(options)
|
|
202
|
+
|
|
203
|
+
this.$baseContent = $(options.baseDom)
|
|
204
|
+
this.$tipChild = info.$tipChild
|
|
205
|
+
this.$tipContent = info.$tipContent
|
|
206
|
+
this.tipHeight = this.$tipChild.height()
|
|
207
|
+
this.tipWidth = this.getTipChildWidth()
|
|
208
|
+
|
|
209
|
+
if (windowEnv === 'pix') {
|
|
210
|
+
this.basePosition = this.$baseContent.position()
|
|
211
|
+
} else {
|
|
212
|
+
this.basePosition = this.$baseContent.get(0).getBoundingClientRect()
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
this.clearOther = 'clearOther' in options ? options.clearOther : true
|
|
216
|
+
|
|
217
|
+
this.baseDom = this.$baseContent.length > 0 ? this.$baseContent[0] : null
|
|
218
|
+
|
|
219
|
+
this.initEvent(isTemp)
|
|
220
|
+
|
|
221
|
+
// 获取tips元素的偏移坐标
|
|
222
|
+
let leftTip = 0
|
|
223
|
+
let topTip = 0
|
|
224
|
+
if (['top', 'bottom'].includes(options.dir)) {
|
|
225
|
+
leftTip = this.getBasePosition().left;
|
|
226
|
+
topTip = this.getTipPosition(options)
|
|
227
|
+
} else {
|
|
228
|
+
leftTip = this.getTipPosition(options)
|
|
229
|
+
topTip = self.autoTop();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
this.$tipChild.appendTo(this.$tipContent)
|
|
233
|
+
|
|
234
|
+
this.$tipContent.css({
|
|
235
|
+
left: leftTip + 'px',
|
|
236
|
+
top: topTip + 'px',
|
|
237
|
+
width: self.tipWidth + 'px',
|
|
238
|
+
height: self.tipHeight + 'px',
|
|
239
|
+
})
|
|
240
|
+
// 此时 tipContent是隐藏, tipChild已设置成展示
|
|
241
|
+
const resizeInfo = {
|
|
242
|
+
func: this.resizePosition,
|
|
243
|
+
obj: this
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
addResizeFunc(resizeInfo)
|
|
247
|
+
addScrollFunc(resizeInfo)
|
|
248
|
+
|
|
249
|
+
this.addScrollParents();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
tip.prototype.initEvent = function (isTemp = false) {
|
|
253
|
+
if (isTemp) {
|
|
254
|
+
return false
|
|
255
|
+
}
|
|
256
|
+
const self = this
|
|
257
|
+
let openClick = true
|
|
258
|
+
let openClickCall = null
|
|
259
|
+
if (this.options.event) {
|
|
260
|
+
if ('openClick' in this.options.event) {
|
|
261
|
+
openClick = this.options.event.openClick
|
|
262
|
+
}
|
|
263
|
+
if ('click' in this.options.event) {
|
|
264
|
+
openClickCall = this.options.event.click
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
this.$baseContent.on('click', function () {
|
|
268
|
+
if (openClick) {
|
|
269
|
+
if (self.$tipContent.css('display') === 'none') {
|
|
270
|
+
self.show()
|
|
271
|
+
} else {
|
|
272
|
+
self.hide()
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (typeof openClickCall === 'function') {
|
|
276
|
+
openClickCall.call(this, self)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
})
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
tip.prototype.show = async function (needResize = true) {
|
|
283
|
+
if (needResize) {
|
|
284
|
+
//重新计算位置
|
|
285
|
+
await this.resizePosition();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
this.$tipChild.css('opacity', 1)
|
|
289
|
+
this.$tipContent.css({
|
|
290
|
+
opacity: 1
|
|
291
|
+
}).show().parent().show()
|
|
292
|
+
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// 重新计算位置 - 也用作生成好tips之后,页面变化的resize事件
|
|
296
|
+
tip.prototype.resizePosition = function () {
|
|
297
|
+
if (!this.$tipContent) {
|
|
298
|
+
return
|
|
299
|
+
}
|
|
300
|
+
this.basePosition = this.getBasePosition();
|
|
301
|
+
// 取不到内容 或者为null 则不处理了
|
|
302
|
+
if (this.basePosition === null) {
|
|
303
|
+
return
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// 获取tips元素的偏移坐标
|
|
307
|
+
let leftTip = 0
|
|
308
|
+
let topTip = 0
|
|
309
|
+
const options = this.options
|
|
310
|
+
|
|
311
|
+
const funcTip = () => {
|
|
312
|
+
if (['top', 'bottom'].includes(options.dir)) {
|
|
313
|
+
leftTip = this.getBasePosition().left;
|
|
314
|
+
topTip = this.getTipPosition(options)
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
leftTip = this.getTipPosition(options)
|
|
318
|
+
topTip = this.autoTop();
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (this.$tipContent && this.$tipContent.css('display') !== 'none') {
|
|
323
|
+
funcTip();
|
|
324
|
+
return new Promise(resolve => {
|
|
325
|
+
this.$tipContent.css({
|
|
326
|
+
left: leftTip + 'px',
|
|
327
|
+
top: topTip + 'px',
|
|
328
|
+
})
|
|
329
|
+
resolve()
|
|
330
|
+
})
|
|
331
|
+
} else {
|
|
332
|
+
// 再次把子内容移出来,重新计算位置
|
|
333
|
+
this.$tipChild.css({ 'opacity': 0 }).appendTo($(document.body))
|
|
334
|
+
funcTip();
|
|
335
|
+
return new Promise(resolve => {
|
|
336
|
+
setTimeout(() => {
|
|
337
|
+
if (this.$tipContent) {
|
|
338
|
+
|
|
339
|
+
this.$tipChild.appendTo(this.$tipContent).css({ 'opacity': 1 })
|
|
340
|
+
this.$tipContent.css({
|
|
341
|
+
left: leftTip + 'px',
|
|
342
|
+
top: topTip + 'px',
|
|
343
|
+
width: this.tipWidth + 'px',
|
|
344
|
+
height: this.tipHeight + 'px',
|
|
345
|
+
})
|
|
346
|
+
}
|
|
347
|
+
resolve(true)
|
|
348
|
+
})
|
|
349
|
+
})
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
tip.prototype.remove = function () {
|
|
356
|
+
if (this.$tipContent) {
|
|
357
|
+
this.$tipContent.remove();
|
|
358
|
+
}
|
|
359
|
+
if (this.$baseContent) {
|
|
360
|
+
this.$baseContent.off('click');
|
|
361
|
+
}
|
|
362
|
+
const resizeInfo = {
|
|
363
|
+
func: this.resizePosition,
|
|
364
|
+
obj: this
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
removeResizeFunc(resizeInfo)
|
|
368
|
+
removeScrollFunc(resizeInfo)
|
|
369
|
+
this.removeScrollParents()
|
|
370
|
+
|
|
371
|
+
setTimeout(() => {
|
|
372
|
+
// 宏任务,body click触发时 让对象的$tipContent还存在
|
|
373
|
+
this.$tipContent = null
|
|
374
|
+
})
|
|
375
|
+
|
|
376
|
+
if (tmp2TipsArr.indexOf(this) === -1) {
|
|
377
|
+
tmp2TipsArr.push(this)
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
tip.prototype.hide = function () {
|
|
382
|
+
this.$tipContent.hide();
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
tip.prototype.isHide = function () {
|
|
386
|
+
return this.$tipContent.css('display') === 'none'
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
tip.prototype.isRemove = function () {
|
|
390
|
+
return this.$tipContent === null
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// 计算左侧空间是否足够
|
|
394
|
+
tip.prototype.spaceLeft = function (options) {
|
|
395
|
+
if (this.basePosition.left - options.position.x > this.getTipChildWidth()) {
|
|
396
|
+
return true
|
|
397
|
+
}
|
|
398
|
+
return false
|
|
399
|
+
}
|
|
400
|
+
// 计算右侧空间是否足够
|
|
401
|
+
tip.prototype.spaceRight = function (options) {
|
|
402
|
+
if ($(document.body).width() - this.basePosition.left - options.position.x - this.$baseContent.width() > this.getTipChildWidth()) {
|
|
403
|
+
return true
|
|
404
|
+
}
|
|
405
|
+
return false
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// 获取具体的起始位置
|
|
409
|
+
// 横向以left为基准
|
|
410
|
+
tip.prototype.getSpaceDirNum = function (options, dir = 'left') {
|
|
411
|
+
const basePosition = this.getBasePosition()
|
|
412
|
+
if (dir === 'left') {
|
|
413
|
+
return basePosition.left - options.position.x - this.getTipChildWidth()
|
|
414
|
+
} else {
|
|
415
|
+
return basePosition.left + options.position.x + this.$baseContent.width()
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// 获取要取得的tip元素的left位置
|
|
420
|
+
tip.prototype.getTipPosition = function (options) {
|
|
421
|
+
// 如果靠左,计算偏移量是否符合条件
|
|
422
|
+
if (options.dir === 'left') {
|
|
423
|
+
// 首先尝试左侧侧放置是否足够
|
|
424
|
+
if (this.spaceLeft(options)) {
|
|
425
|
+
return this.getSpaceDirNum(options, 'left')
|
|
426
|
+
} else if (this.spaceRight(options)) {
|
|
427
|
+
return this.getSpaceDirNum(options, 'right')
|
|
428
|
+
} else {
|
|
429
|
+
// 兜底放置在左侧
|
|
430
|
+
return 0
|
|
431
|
+
}
|
|
432
|
+
} else if (options.dir === 'top') {
|
|
433
|
+
return this.autoTop() - this.getTipChildHeight();
|
|
434
|
+
} else if (options.dir === 'bottom') {
|
|
435
|
+
return this.autoTop() + this.$baseContent.height();
|
|
436
|
+
} else {
|
|
437
|
+
// 兜底是右侧
|
|
438
|
+
// 首先尝试右侧放置是否足够
|
|
439
|
+
if (this.spaceRight(options)) {
|
|
440
|
+
return this.getSpaceDirNum(options, 'right')
|
|
441
|
+
} else if (this.spaceLeft(options)) {
|
|
442
|
+
return this.getSpaceDirNum(options, 'left')
|
|
443
|
+
} else {
|
|
444
|
+
// 兜底放置在右侧
|
|
445
|
+
return $(document.body).width() - options.position.x - this.getTipChildWidth()
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const getAlreadyTip = (baseDom) => {
|
|
451
|
+
for (let i = 0; i < tmp2TipsArr.length; i++) {
|
|
452
|
+
// 意味着刚删除,还没有触发body click事件,没有整体做清空
|
|
453
|
+
if (baseDom === tmp2TipsArr[i].baseDom) {
|
|
454
|
+
return false
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
for (let i = 0; i < tipsArr.length; i++) {
|
|
458
|
+
if (baseDom === tipsArr[i].baseDom) {
|
|
459
|
+
return tipsArr[i]
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
for (let i = 0; i < tmpTipsArr.length; i++) {
|
|
463
|
+
if (baseDom === tmpTipsArr[i].baseDom) {
|
|
464
|
+
if (tmpTipsArr[i].$tipContent) {
|
|
465
|
+
return tmpTipsArr[i]
|
|
466
|
+
} else {
|
|
467
|
+
tmpTipsArr.splice(i, 1)
|
|
468
|
+
return false
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return null
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// 计算top距离
|
|
476
|
+
tip.prototype.autoTop = function () {
|
|
477
|
+
const h = window.innerHeight || $(document.body).height()
|
|
478
|
+
const top = this.basePosition.top + this.options.position.y
|
|
479
|
+
|
|
480
|
+
if (this.tipHeight <= 0) {
|
|
481
|
+
// 如果计算的这个tipHeight高度不准确,那么取tipContent tipChild再计算一次
|
|
482
|
+
const tipContentHeight = this.$tipContent.height()
|
|
483
|
+
if (tipContentHeight > 0) {
|
|
484
|
+
this.tipHeight = tipContentHeight
|
|
485
|
+
} else {
|
|
486
|
+
const tipChildtHeight = this.$tipChild.height()
|
|
487
|
+
if (tipChildtHeight > 0) {
|
|
488
|
+
this.tipHeight = tipChildtHeight
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
const hTop = h - this.tipHeight - 4;
|
|
493
|
+
|
|
494
|
+
if (hTop < top) {
|
|
495
|
+
return hTop
|
|
496
|
+
}
|
|
497
|
+
return top
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// 给基础元素的父元素及祖先元素增加scroll事件,监听位移
|
|
501
|
+
tip.prototype.addScrollParents = function () {
|
|
502
|
+
let $parent = this.$baseContent.parent()
|
|
503
|
+
this.scrollFn = () => {
|
|
504
|
+
return this.resizePosition()
|
|
505
|
+
}
|
|
506
|
+
while ($parent[0] !== document.body) {
|
|
507
|
+
$parent[0].addEventListener("scroll", this.scrollFn);
|
|
508
|
+
$parent = $parent.parent()
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
tip.prototype.removeScrollParents = function () {
|
|
513
|
+
let $parent = this.$baseContent.parent()
|
|
514
|
+
while ($parent[0] != null && $parent[0] !== document.body) {
|
|
515
|
+
$parent[0].removeEventListener("scroll", this.scrollFn);
|
|
516
|
+
$parent = $parent.parent()
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// 获取tip内容元素的宽度
|
|
521
|
+
tip.prototype.getTipChildWidth = function () {
|
|
522
|
+
if (windowEnv === 'pix') {
|
|
523
|
+
return this.$tipChild.width()
|
|
524
|
+
} else {
|
|
525
|
+
return this.$tipChild.outerWidth()
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// 获取tip内容元素的高度
|
|
531
|
+
tip.prototype.getTipChildHeight = function () {
|
|
532
|
+
if (windowEnv === 'pix') {
|
|
533
|
+
return this.$tipChild.height()
|
|
534
|
+
} else {
|
|
535
|
+
return this.$tipChild.outerHeight()
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// 获取参照元素的位置
|
|
541
|
+
tip.prototype.getBasePosition = function () {
|
|
542
|
+
if (windowEnv === 'pix') {
|
|
543
|
+
return this.$baseContent.position()
|
|
544
|
+
} else {
|
|
545
|
+
return this.$baseContent.get(0).getBoundingClientRect()
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const isClick = (tipInfo, e) => {
|
|
550
|
+
if (tipInfo.$baseContent[0] === e.target && tipInfo.$tipContent) {
|
|
551
|
+
return true
|
|
552
|
+
}
|
|
553
|
+
if (tipInfo.$baseContent.find(e.target)[0] === e.target && tipInfo.$tipContent) {
|
|
554
|
+
return true
|
|
555
|
+
}
|
|
556
|
+
return false
|
|
557
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export const nextAnimationFrame = () => {
|
|
2
|
+
return new Promise(resolve => {
|
|
3
|
+
requestAnimationFrame(() => {
|
|
4
|
+
resolve();
|
|
5
|
+
});
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// 进行resize有关的功能设置
|
|
10
|
+
const resizeFunc = []
|
|
11
|
+
export function addResizeFunc(options){
|
|
12
|
+
if(options.func && options.obj){
|
|
13
|
+
resizeFunc.push(options)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function removeResizeFunc(options){
|
|
18
|
+
for(let i=0;i<resizeFunc.length;i++){
|
|
19
|
+
if(options.obj === resizeFunc[i].obj){
|
|
20
|
+
resizeFunc.splice(i,1)
|
|
21
|
+
i = i-1;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function startEventResize(){
|
|
27
|
+
// 监听 window 的 resize 事件
|
|
28
|
+
window.addEventListener('resize', function(event) {
|
|
29
|
+
resizeFunc.forEach(item=>{
|
|
30
|
+
if(item.func && item.obj){
|
|
31
|
+
item.func.call(item.obj)
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 进行onscroll有关的功能设置
|
|
38
|
+
const scrollFunc = []
|
|
39
|
+
export function addScrollFunc(options){
|
|
40
|
+
if(options.func && options.obj){
|
|
41
|
+
scrollFunc.push(options)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function removeScrollFunc(options){
|
|
46
|
+
for(let i=0;i<scrollFunc.length;i++){
|
|
47
|
+
if(options.obj === scrollFunc[i].obj){
|
|
48
|
+
scrollFunc.splice(i,1)
|
|
49
|
+
i = i-1;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function startEventScroll($){
|
|
55
|
+
const handler = function() {
|
|
56
|
+
scrollFunc.forEach(item=>{
|
|
57
|
+
if(item.func && item.obj){
|
|
58
|
+
item.func.call(item.obj)
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
// 监听 window 的 scroll 事件
|
|
63
|
+
$(document.body).on('scroll', handler);
|
|
64
|
+
window.addEventListener('scroll', handler);
|
|
65
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|