From 20e07082e19a068388378206d4678dd3a1b7bbc4 Mon Sep 17 00:00:00 2001 From: chenjiajian <770230504@qq.com> Date: Tue, 21 Mar 2023 18:18:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96scroll=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scroll/index.js | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/scroll/index.js b/src/scroll/index.js index 85634b1..07ba7c2 100644 --- a/src/scroll/index.js +++ b/src/scroll/index.js @@ -8,13 +8,7 @@ import { css, bind, html, unbind, Component } from '@bd/core' class Scroll extends Component { static props = { - axis: { - type: String, - default: 'xy', - observer(val) { - this.onAxisChange(val) - } - }, + axis: 'xy', distance: 0 } dragging = false @@ -23,7 +17,7 @@ class Scroll extends Component { css` :host { position: relative; - overflow: hidden; + overflow: auto; display: block; &::-webkit-scrollbar { display: none; @@ -34,7 +28,6 @@ class Scroll extends Component { position: relative; } .scroll-bar { - display: none; position: absolute; background: #909399; width: 0; @@ -64,16 +57,22 @@ class Scroll extends Component { visibility: hidden; } } + :host([axis='x']) { + overflow-x: auto; + overflow-y: hidden; + .vertical { + display: none; + } + } + :host([axis='y']) { + overflow-y: auto; + overflow-x: hidden; + .horizon { + display: none; + } + } ` ] - onAxisChange(val) { - this.style.overflow = 'hidden' - if (val === 'xy') { - this.style.overflow = 'auto' - } else { - this.style[`overflow-${val}`] = 'auto' - } - } render() { return html` @@ -193,12 +192,10 @@ class Scroll extends Component { this.horizonWidth = 0 } if (axis.includes('x')) { - horizon.style.display = 'block' horizon.style.width = this.horizonWidth + 'px' bind(horizon, 'mousedown', this.onmousedown.bind(this)) } if (axis.includes('y')) { - vertical.style.display = 'block' vertical.style.height = this.verticalHeight + 'px' bind(vertical, 'mousedown', this.onmousedown.bind(this)) }