简体   繁体   English

如何使div充当滚动条句柄

[英]How to make a div act as a scrollbar handle

I'm trying to make a highly customized 'scrollbar' (more like a navbar that scrolls) for my application, but I can't find any plugins that fit my needs. 我正在尝试为我的应用程序制作一个高度自定义的“滚动条”(更像是滚动的导航栏),但我找不到任何符合我需求的插件。

My questions are: 我的问题是:

  • What function is being invoked here that is making the window scroll once the red div is translated? 这里调用什么函数,一旦红色div被翻译, window滚动? (is it $.scrollTop() , if so, how do I animate that?) (是$.scrollTop() ,如果是这样,我该如何设置动画?)
  • Is there an ultimate plugin that I'm not privy to that simplifies custom navigation of a scrollable element (meaning drag-to-scroll , arrow key , and/or minimap navigation support, preferably horizontal and vertical w/ momentum/easing + bounce). 是否有一个我不知情的终极插件,简化了可滚动元素的自定义导航 (意味着拖动到滚动箭头键和/或小地图导航支持,最好是水平和垂直w /动量/缓和+反弹) 。

I've seen IScroll , but it's no longer supported as of ~2 years and lacks mouse wheel easing and bounce. 我见过IScroll ,但它已经不再支持〜2年了,并且没有鼠标滚轮缓和和反弹。 Am I missing something? 我错过了什么吗? Thanks for the help! 谢谢您的帮助!

Edit : Turns out it is $.scrollTop for the first question. 编辑 :对于第一个问题,结果是$.scrollTop

Try this, seems like what you were looking for: 尝试这个,看起来像你在寻找:

http://codepen.io/blyk/pen/JGtfd http://codepen.io/blyk/pen/JGtfd

$(document).ready(function(){

   $("div").mouseenter(function(){
     var id = $(this).attr('id');
     $('a').removeClass('active');
     $("[href=#"+id+"]").addClass('active');
   });

});

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

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