简体   繁体   English

滚动时找到滚动位置

[英]Find the scroll position when scrolling

I'm using this library for the scroll https://kingsora.github.io .我正在使用此库进行滚动https://kingsora.github.io How do you know that the element is completely scrolled?你怎么知道元素完全滚动了? I can nyyati only the initial point where scroll = 0, but how do you know that the element is scrolled to the end?我只能确定滚动 = 0 的初始点,但是你怎么知道元素滚动到最后呢?

var instance = $("#road-scroll")
 .overlayScrollbars({
  callbacks: {
   onScrollStop: function(e) {
    scrollLeft = e.target.scrollLeft;

    if (scrollLeft === 0) {
      btnL.removeClass("btn-active");
    }

    if (scrollLeft > 0) {
      btnL.addClass("btn-active");
    }

  }
 }
})
.overlayScrollbars();

Answer:回答:

 var instance = $("#road-scroll")
  .overlayScrollbars({
  callbacks: {
   onScrollStop: function(e) {
    scrollLeft = e.target.scrollLeft;
    var scrollInfo = instance.scroll();
    let max = scrollInfo.x.max;

    if (scrollLeft === 0) {
      btnL.removeClass("btn-active");
    }

    if (scrollLeft > 0) {
      btnL.addClass("btn-active");
    }

    if (scrollLeft >= max) {
      btnR.removeClass("btn-active");
    }

    if (scrollLeft < max) {
      btnR.addClass("btn-active");
    }

   }
  }
 })
.overlayScrollbars();

The answer should be actually <instance>.scroll.max.x and not x.max as per @Андрей Охотников's answer:根据@Андрей Охотников 的回答,答案实际上应该是<instance>.scroll.max.x而不是x.max

在此处输入图片说明

const scrollBar = $(jsScrollPageContainer).overlayScrollbars({
    className: "os-theme-dark",
    callbacks: {
        onScroll: function(e) {
            const scrollInfo = scrollBar.scroll();
            const max = scrollInfo.max.x;
            const scrollLeft = e.target.scrollLeft; // same as `scrollInfo.position.x`
            const scrollTop = e.target.scrollTop; // same as `scrollInfo.position.y`

            // other logic
        }
    }
}).overlayScrollbars();

Complete object for reference:完整对象供参考:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM