Giter VIP home page Giter VIP logo

minapp-scroll's Introduction

minapp-scroll

自定义小程序滚动条 隐藏默认滚动条

布局

外边包一层壳子 scroll-view 宽比外边壳子大20像素 scroll-inner 跟外边壳子的宽度一样 就可以达到隐藏默认滚动条的效果

js

监听 scroll事件

如果用户超过2秒不滚动, 就隐藏

这个只是简单的竖向自定义滚动条demo

效果图片

只是加了一个状态

对应的 barHt 也要动态获取了

   scrollInit() {
    wx.createSelectorQuery().select('#scroll').boundingClientRect((rect) => {
      this.setData({
        scrollBox: rect
      })
    }).exec()
    wx.createSelectorQuery().select('#bar').boundingClientRect((rect) => {
      this.setData({
        barHt: rect.height
      })
    }).exec()
    
  },
  bindscroll: function(e) {
    console.log(e)
    let scrollBound = this.data.scrollBox
    let scrollHeight = e.detail.scrollHeight
    let scrollTop = e.detail.scrollTop
    //滚动条bar高度根据显示区域占内容区域的比例显示
    let barHt = this.data.barHt
    let barTop = (scrollTop / (scrollHeight - scrollBound.height) * (scrollBound.height - barHt));
    this.setData({
      barTop: barTop
    })
  },

minapp-scroll's People

Contributors

blendzlq avatar

Stargazers

 avatar  avatar

Forkers

pink0101

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.