Using better-scroll scrolling plug-in in vue

亚连
Release: 2018-06-06 17:36:08
Original
2415 people have browsed it

This article mainly introduces the detailed explanation of vue better-scroll rolling plug-in troubleshooting. Now I will share it with you and give you a reference.

BetterScroll is known as the best mobile scrolling plug-in at present, so its power is definitely there. Otherwise...haha. Personally I feel it's very useful. This article is not about BetterScroll in general, but about scrolling in detail. If you want to learn more about it, please go here.

Scrolling principle

better-scroll What isScrolling principle

better- scroll is a plug-in that focuses on solving the needs of various scrolling scenarios on the mobile terminal (PC is already supported). Its core is based on the implementation of iscroll. Its API design is basically compatible with iscroll. On the basis of iscroll, it has expanded some features and made some performance optimizations.

better-scroll is implemented based on native JS and does not rely on any framework. Its compiled code size is 63kb, 35kb after compression, and only 9kb after gzip. It is a very lightweight JS lib.

The green part is the wrapper, which is the parent container, and it will have a fixed height. The yellow part is content, which is the first child element of the parent container. Its height will increase with the size of the content. Then, when the height of the content does not exceed the height of the parent container, it cannot be scrolled. Once it exceeds the height of the parent container, we can scroll the content area. The principle of horizontal scrolling is to change the fixed height to a fixed width. (No more verbosity here)

Vertical scrolling

Without further ado, let’s go directly to the code.

  
Copy after login

This is a Vue BetterScroll vertical scrolling demo. There are two points to note here.

  1. There can only be one layer of parent p, that is, the container

  2. The parent p must be set to overflow hiding and have a fixed height

Horizontal scrolling

Horizontal scrolling. Compared with vertical scrolling, you need to dynamically obtain the width of the scroll area and directly enter the code.

  
Copy after login

Horizontal scrolling requires attention.

  1. There can only be one layer of parent p, that is, the container

  2. The parent container must set overflow hiding and fixed width

  3. Dynamicly obtain the width of the scroll area

Because of the recent project needs, I checked a lot of information from the Internet but could not solve my problem. The BetterScroll official website does not provide actual demo reference, so I took advantage of my break to write this article. Hope it's useful to you. If you need a specific demo, please move here and don’t forget to give it a star. Writing articles is not easy, so give it a like!

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to integrate vue into jquery/bootstrap projects?

About the use of vue-fontawesome in vue.js

Use JS to add new elements to the node

The above is the detailed content of Using better-scroll scrolling plug-in in vue. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn