Skip to content

Commit

Permalink
perf(scrollbar): use transform replace top and left
Browse files Browse the repository at this point in the history
  • Loading branch information
qmhc committed Jul 6, 2021
1 parent f0dab34 commit 5a0e272
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions components/scroll/scrollbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,16 @@ export default defineComponent({
const style: CSSProperties = {
backgroundColor: props.barColor
}
const position = `${((100 - props.barLength) * currentScroll.value) / 100}%`
const position = `${((100 - props.barLength) * currentScroll.value) / props.barLength}%`
const length = `${props.barLength}%`
if (type.value === ScrollbarType.VERTICAL) {
style.top = position
style.height = length
style.transform = `translate3d(0, ${position}, 0)`
} else {
style.left = position
// style.left = position
style.width = length
style.transform = `translate3d(${position}, 0, 0)`
}
if (isDefined(props.duration) && props.duration >= 0) {
Expand Down
2 changes: 2 additions & 0 deletions style/scroll.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
&__wrapper {
position: relative;
vertical-align: top;
will-change: transform;
transition-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);
transition-duration: 140ms;
transition-property: transform;

&--scrolling,
&--using-bar,
Expand Down
4 changes: 2 additions & 2 deletions style/scrollbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@
cursor: pointer;
background-color: $vxp-scrollbar-color-bg-bar;
border-radius: 3px;
will-change: transform;
transition:
width $vxp-transition-base,
height $vxp-transition-base,
$vxp-transition-opacity-base,
top 200ms $timing,
left 200ms $timing;
transform 140ms $timing;

&:hover {
opacity: 0.8;
Expand Down

0 comments on commit 5a0e272

Please sign in to comment.