This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
bytedo
/
wcui
Archived
1
0
Fork 0

滚动组件支持翻页

old
宇天 2020-07-30 15:29:41 +08:00
parent 594d9956ac
commit 0234144dfb
2 changed files with 30 additions and 7 deletions

View File

@ -331,13 +331,6 @@ export default class Neditor {
return return
} }
log(
this.__EDITOR__,
'------',
val,
(type === 'boolean' && val) || type !== 'boolean'
)
if ((type === 'boolean' && val) || type !== 'boolean') { if ((type === 'boolean' && val) || type !== 'boolean') {
this.props.disabled = true this.props.disabled = true
this.setAttribute('disabled', '') this.setAttribute('disabled', '')

View File

@ -243,6 +243,10 @@ export default class Scroll {
this.__Y__.style.height = yh + 'px' this.__Y__.style.height = yh + 'px'
}) })
this._inactiveFn = $.bind(this.__BOX__, 'mouseleave', ev => {
delete this._active
})
// 鼠标滚动事件 // 鼠标滚动事件
this._wheelFn = $.bind(this.__BOX__, 'wheel', ev => { this._wheelFn = $.bind(this.__BOX__, 'wheel', ev => {
// 禁用状态, 不允许滚动 // 禁用状态, 不允许滚动
@ -343,6 +347,8 @@ export default class Scroll {
} }
} }
this._active = true
this.stamp = now this.stamp = now
this.dispatchEvent( this.dispatchEvent(
new CustomEvent('scroll', { new CustomEvent('scroll', {
@ -362,6 +368,7 @@ export default class Scroll {
} }
if (startY !== null) { if (startY !== null) {
this._active = true
moveY = this._fetchScrollY(thumbY + ev.pageY - startY) moveY = this._fetchScrollY(thumbY + ev.pageY - startY)
} }
}, },
@ -400,6 +407,27 @@ export default class Scroll {
$.bind(document, 'mouseup', mouseupFn) $.bind(document, 'mouseup', mouseupFn)
}) })
$.catch(document, 'keydown', ev => {
if (this._active) {
var { oh, sh } = this.props
switch (ev.keyCode) {
case 33: // pageUp
this.scrollTop -= oh
break
case 34: // pageDown
this.scrollTop += oh
break
case 35: // End
this.scrollTop = sh
break
case 36: // Home
this.scrollTop = 0
break
}
ev.preventDefault()
}
})
this.__observer = new MutationObserver(this._initFn) this.__observer = new MutationObserver(this._initFn)
this.__observer.observe(this, { this.__observer.observe(this, {
childList: true, childList: true,
@ -410,7 +438,9 @@ export default class Scroll {
unmount() { unmount() {
this.__observer.disconnect() this.__observer.disconnect()
$.unbind(this.__BOX__, 'mouseenter', this._initFn) $.unbind(this.__BOX__, 'mouseenter', this._initFn)
$.unbind(this.__BOX__, 'mouseleave', this._inactiveFn)
$.unbind(this.__BOX__, 'wheel', this._wheelFn) $.unbind(this.__BOX__, 'wheel', this._wheelFn)
} }