packages/vuepress-docs/docs/en-US/guide/base-scroll-options.md
BetterScroll supports rich options configuration, you can pass them in the second parameter when initializing, for example:
import BScroll from '@better-scroll/core'
let scroll = new BScroll('.wrapper',{
scrollY: true,
click: true
})
This implements a list of vertical clickable scrolling effects. so let's list the parameters supported by BetterScroll.
number0number0booleanfalsebooleantruebooleanfalsefreeScroll to true.// finger startpoint -> e1: { pageX: 120, pageY: 120 }
// finger endpoint -> e2: { pageX: 121, pageY: 140 }
// offsetX: e2.pageX - e1.pageX = 1
// offsetY: e2.pageY - e1.pageY = 20
// if freeScroll is false, due to offsetY > offsetX + directionLockThreshold
// offsetX is fixed to be 0, only calculate offsetY, thus do a vertical scroll!
number5freeScroll is false, we need to lock the scrolling only in one direction, we calculate the numerical difference between the absolute values of horizontal axis and vertical axis' scrolling distance at the initialization time of scrolling. When the value of the numerical difference is greater than directionLockThreshold, the lock direction can be determined.directionLockThreshold is invalid and will always be 0.string''vertical | horizontaleventPassthrough will cause some other settings to be invalid, be careful when using it.booleanfalsetrue. And then BetterScroll will add a private attribute called _constructed to the dispatched event whose value is true.boolean | Objectfalsedelay can be modified. dblclick: {
delay: 300
}
string''boolean | Objecttrue bounce: {
top: true,
bottom: true,
left: true,
right: true
}
bounce can support the effect of closing the back of some edges. You can set the key of the corresponding side to false.
:::tip
If you want to conveniently set all edges to true or false, you only need to set bounce to true or false.
:::
number800 (ms, modification is not recommended)booleantruenumber300 (ms)momentumLimitTime resulting in the momentum animation.number15 (px)momentumLimitTime resulting in the momentum animation.number2500 (ms)number500 (ms)number0.0015number200flickLimitTime, it is considered as a flick action.number100flickLimitDistance, it is considered as a flick actionnumber60 (ms)number01 | 2 | 3useTransition is true.// There are two scenarios for dispatching scroll:
// 1. The finger acts on the scrolling area (content DOM),
// 2. Invoke the scrollTo method or trigger the momentum scroll animation (in fact, the implementation is still Invoking the scrollTo method)
// For the v2.1.0, the probeType has been unified
// The probeType is:
// 0, scroll event will not be dispatched at any time,
// 1, and only when the finger is moving on the scroll area, a scroll event is dispatched every momentumLimitTime milliseconds.
// 2, and only when the finger is moving on the scroll area, a scroll event is dispatched all the time.
// 3, scroll events are dispatched at any time, including invoking scrollTo or triggering momentum
booleantruepreventDefault() when events are fired. This should be left true unless you really know what you are doing.{ tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT|AUDIO)$/ }{tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT|AUDIO)$/} represents that default behaviours of elements with tagnames like 'input', 'textarea', 'button', 'select', 'audio' will not be inhibited{className:/(^|\s)test(\s|$)/}.Object{ tagName: /^TEXTAREA$/ }textarea, the user's expectation should be that sliding textarea should not cause bs scrolling. If the manipulated DOM (eg:textarea tag) hits the configured rule, bs won't scroll.{className:/(^|\s)test(\s|$)/}.booleantruetranslateZ(1px) to the transform CSS property. This greatly increases performance especially on mobile and achieve a good scrolling effect.booleantruerequestAnimationFrame to do animation.booleanfalsetouchmove event is normally bound to the document and not the scroll wrapper. When you move the cursor out of the wrapper the scrolling keeps going(only works in PC). This is usually what you want, but you can also bind the move event to wrapper itself. Doing so as soon as the cursor leaves the wrapper the scroll stops.booleantrue and mouse event will not be listened. While in PC environment, disableMouse will be false and mouse event will be listened.booleandisableTouch will be false and touch event will be listened. While in PC environment, disableMouse will be true and touch event will not be listened. We suggest not modifying this unless you konw what you are doing.::: warning Considering some specific scenarios of the user, such as the tablet needs to support the touch event, the tablet with mouse has to support the mouse event, In other words, if you need to listen to the touch and mouse events at the same time, then the instantiation of BetterScroll needs to be configured as follows:
let bs = new BScroll('.wrapper', {
disableMouse: false,
disableTouch: false
})
Due to the different bottom-level implementation logic of different devices and different browser environments, BetterScroll's internal calculations of whether to listen to touch or mouse events may make wrong judgment, so you can solve this type of problem according to the above option configuration.
:::
booleantruebooleanfalsebooleanfalsecontent element instead of the container wrapper, which is mostly used in movable.number5touchend event may not be triggered when sliding out of the viewport, so the function of autoEndDistance is to automatically call the touchend event when the finger is about to leave the current viewport. When the default distance is 5px from the boundary, the scrolling ends.number1 / 3number0wrapper as the content. By default, BetterScroll uses the first child element of the wrapper as the content.<div class="wrapper">
<div class="content1">
<div class="conten1-item">1.1</div>
<div class="conten1-item">1.2</div>
</div>
<div class="content2">
<div class="conten2-item">2.1</div>
<div class="conten2-item">2.2</div>
</div>
</div>
// For the above DOM structure, when BetterScroll version <= 2.0.3, only div.content1 is used as content
// When the version is >= 2.0.4, content can be specified through 'specifiedIndexAsContent'
let bs = new BScroll('.wrapper', {
specifiedIndexAsContent: 1 // use div.content2 as BetterScroll's content
})
1 | 2 | 3 | 41<style>
/* wrapper's parent DOM rotated*/
.container {
transform: rotate(90deg);
}
</style>
<div class="container">
<div class="wrapper">
<div class="content">
<div class="content-item">1.1</div>
<div class="content-item">1.2</div>
</div>
</div>
</div>
let bs = new BScroll('.wrapper', {
quadrant: 2
})
wrapper is (315, 45], the quadrant can keep the default value;wrapper is (45, 135],Especially 90 degrees, the quadrant must be 2;wrapper is (135, 225],Especially 180 degrees, the quadrant must be 3;wrapper is (225, 315],Especially 270 degrees, the quadrant must be 4;coordinateTransformation hook.let bs = new BScroll('.wrapper', {
quadrant: 1 // default value
})
bs.scroller.actions.hooks.on(
bs.scroller.actions.hooks.eventTypes.coordinateTransformation,
(transformateDeltaData) => {
// get user finger moved distance
const originDeltaX = transformateDeltaData.deltaX
const originDeltaY = transformateDeltaData.deltaY
// apply transformation
transformateDeltaData.deltaX = originDeltaY
transformateDeltaData.deltaY = originDeltaX
// transformateDeltaData.deltaX will be used as content DOM style's translateX
// transformateDeltaData.deltaY will be used as content DOM style's translateY
}
)
For example: Use CSS to flip the horizontal scrolling BetterScroll.
<demo qrcode-url="core/horizontal-rotated"> <template slot="code-template"> <<< @/examples/vue/components/core/horizontal-rotated.vue?template </template> <template slot="code-script"> <<< @/examples/vue/components/core/horizontal-rotated.vue?script </template> <template slot="code-style"> <<< @/examples/vue/components/core/horizontal-rotated.vue?style </template> <core-horizontal-rotated slot="demo"></core-horizontal-rotated> </demo>