关键词搜索

源码搜索 ×
×

NiceScroll文档阅读笔记-NiceScroll(3.7.6)基本使用

发布2022-02-10浏览953次

详情内容

前言

官方已经给出很好的文档了。在此本人总结下,方便以后查阅:

GitHub - inuyaksa/jquery.nicescroll: nicescroll plugin for jquery - scrollbars like iphone/ipad

nicescroll是一个jquery的插件,需要先包含jquery,再使用这框架,NiceScroller可用于jQuery1.xhttps://cdn.jxasp.com:9143/image/2.x/3.x版本,但不能在slim版本中使用。

使用

首先需要先保护jQuery,,然后再把jquery.nicesroll.min.js和zoomico.png放到项目中,注意,zoomico.png要和jquery.nicescroll.min.js放到同一个目录下。

注意:如果不需要使用NiceScroll提供了zoom功能,就不需要加入zoomic.png图片。

通常在document的ready的时候的初始化NiceScroll

  1. // 1. Simple mode, it styles document scrollbar:【直接替换传统的scroll】
  2. $(function() {
  3. $("body").niceScroll();
  4. });
  5. // 2. Instance with object returned:【获取body中替换的NiceScroll对象】
  6. var nice = false;
  7. $(function() {
  8. nice = $("body").niceScroll();
  9. });
  10. // 3. Style a DIV and change cursor color:【改变div的style】
  11. $(function() {
  12. $("#thisdiv").niceScroll({cursorcolor:"#00F"});
  13. });
  14. // 4. DIV with "wrapper", formed by two divs, the first is the vieport, the latter is the content:【div嵌套时的用法,外层的叫viewport,内层的是warpper】
  15. $(function() {
  16. $("#viewportdiv").niceScroll("#wrapperdiv",{cursorcolor:"#00F"});
  17. });
  18. // 5. Get nicescroll object:【获取NiceScroll对象】
  19. var nice = $("#mydiv").getNiceScroll();
  20. // 6. Hide scrollbars:【隐藏Scrollbars】
  21. $("#mydiv").getNiceScroll().hide();
  22. // 7. Check for scrollbars resize (when content or position have changed):【当内容和位置发生改变时,就要使用resize这个函数了】
  23. $("#mydiv").getNiceScroll().resize();
  24. // 8. Scrolling to a position:【获取sroll的位置,x轴和y轴】
  25. $("#mydiv").getNiceScroll(0).doScrollLeft(x, duration); // Scroll X Axis
  26. $("#mydiv").getNiceScroll(0).doScrollTop(y, duration); // Scroll Y Axis

NiceScroll相关参数

  1. $("#thisdiv").niceScroll({
  2. cursorcolor: "#424242", // change cursor color in hex
  3. cursoropacitymin: 0, // change opacity when cursor is inactive (scrollabar "hidden" state), range from 1 to 0
  4. cursoropacitymax: 1, // change opacity when cursor is active (scrollabar "visible" state), range from 1 to 0
  5. cursorwidth: "5px", // cursor width in pixel (you can also write "5px")
  6. cursorborder: "1px solid #fff", // css definition for cursor border
  7. cursorborderradius: "5px", // border radius in pixel for cursor
  8. zindex: "auto" | [number], // change z-index for scrollbar div
  9. scrollspeed: 60, // scrolling speed
  10. mousescrollstep: 40, // scrolling speed with mouse wheel (pixel)
  11. touchbehavior: false, // DEPRECATED!! use "emulatetouch"
  12. emulatetouch: false, // enable cursor-drag scrolling like touch devices in desktop computer
  13. hwacceleration: true, // use hardware accelerated scroll when supported
  14. boxzoom: false, // enable zoom for box content
  15. dblclickzoom: true, // (only when boxzoom=true) zoom activated when double click on box
  16. gesturezoom: true, // (only when boxzoom=true and with touch devices) zoom activated when pinch out/in on box
  17. grabcursorenabled: true // (only when touchbehavior=true) display "grab" icon
  18. autohidemode: true, // how hide the scrollbar works, possible values:
  19. true | // hide when no scrolling
  20. "cursor" | // only cursor hidden
  21. false | // do not hide,
  22. "leave" | // hide only if pointer leaves content
  23. "hidden" | // hide always
  24. "scroll", // show only on scroll
  25. background: "", // change css for rail background
  26. iframeautoresize: true, // autoresize iframe on load event
  27. cursorminheight: 32, // set the minimum cursor height (pixel)
  28. preservenativescrolling: true, // you can scroll native scrollable areas with mouse, bubbling mouse wheel event
  29. railoffset: false, // you can add offset top/left for rail position
  30. bouncescroll: false, // (only hw accell) enable scroll bouncing at the end of content as mobile-like
  31. spacebarenabled: true, // enable page down scrolling when space bar has pressed
  32. railpadding: { top: 0, right: 0, left: 0, bottom: 0 }, // set padding for rail bar
  33. disableoutline: true, // for chrome browser, disable outline (orange highlight) when selecting a div with nicescroll
  34. horizrailenabled: true, // nicescroll can manage horizontal scroll
  35. railalign: right, // alignment of vertical rail
  36. railvalign: bottom, // alignment of horizontal rail
  37. enabletranslate3d: true, // nicescroll can use css translate to scroll content
  38. enablemousewheel: true, // nicescroll can manage mouse wheel events
  39. enablekeyboard: true, // nicescroll can manage keyboard events
  40. smoothscroll: true, // scroll with ease movement
  41. sensitiverail: true, // click on rail make a scroll
  42. enablemouselockapi: true, // can use mouse caption lock API (same issue on object dragging)
  43. cursorfixedheight: false, // set fixed height for cursor in pixel
  44. hidecursordelay: 400, // set the delay in microseconds to fading out scrollbars
  45. directionlockdeadzone: 6, // dead zone in pixels for direction lock activation
  46. nativeparentscrolling: true, // detect bottom of content and let parent to scroll, as native scroll does
  47. enablescrollonselection: true, // enable auto-scrolling of content when selection text
  48. cursordragspeed: 0.3, // speed of selection when dragged with cursor
  49. rtlmode: "auto", // horizontal div scrolling starts at left side
  50. cursordragontouch: false, // drag cursor in touch / touchbehavior mode also
  51. oneaxismousemode: "auto", // it permits horizontal scrolling with mousewheel on horizontal only content, if false (vertical-only) mousewheel don't scroll horizontally, if value is auto detects two-axis mouse
  52. scriptpath: "" // define custom path for boxmode icons ("" => same script path)
  53. preventmultitouchscrolling: true // prevent scrolling on multitouch events
  54. disablemutationobserver: false // force MutationObserver disabled,
  55. enableobserver: true // enable DOM changing observer, it tries to resize/hide/show when parent or content div had changed
  56. scrollbarid: false // set a custom ID for nicescroll bars
  57. });

此处用个表简单解释下:

propertyvaluedescription
cursorcolor"#424242"改变光标颜色(十六进制)
cursoropacitymin0当光标是无效状态时改变其透明度,范围从1到0
cursoropacitymax1当光标是有效状态时改变其透明度,范围从1到0
cursorwidth"5px"光标的宽度为5像素
cursorborder"1px solid #fff"使用css定义光标包边
cursorborderradius"5px"光标的包边半径(改包边为圆弧)
zindex"auto" | [number]改变光标div的z-index
scrollspeed60光标速率
mousescrollstep40用滚轮滚动的光标速率
touchbehaviorfalse不要使用,改用emulatetouch
emulatetouchfalse开启cursor-darg功能(像触屏滚动的那个效果)
hwaccelerationtruehw是hardware,使用硬件加数功能
boxzoomfalse开启内容放缩功能
dbclickzoomtrue当boxzoom为true时使用,当鼠标双击时zoom为激活状态
gesturezoomtrue当boxzoom为true、touch devices为true时使用
grabcursorenabledtrue当touchbehavior=true时生效,展示"grab"图标
autohidemodetrue
"cursor"
false
"leave"
"hidden"
"scroll"
当不滚动时,scrolllbar被隐藏;
仅光标被隐藏;
不隐藏;
仅隐藏上下箭头;
隐藏;
只有在滚的时候显示
background""使用css定义background
iframeautoresizetrueauto resize
cursorminheight32设置光标最小高度
preservenatviescrollingtrue使用原始的滚轮
radiloffsetfalse为rail postiont添加top/left的偏移
bouncescrollfalse(only hw accell) enable scroll bouncing at the end of content as mobile-like
spacebarenabledtrueenable page down scrolling when space bar has pressed
railpadding{top: 0, right: 0, left 0, bottom: 0}给rail bar设置padding
disableoutlinetruefor chrome browser, disable outline (orange highlight) when selecting a div with nicescroll
horizrailenabledtruenicescroll can manage horizontal scroll
railalignright垂直滑轨的位置
railvalignbottom水平滑轨的位置
enabletranslate3dtruenicescroll can use css translate to scroll content
enablemousewheeltruenicescroll can manage mouse wheel events
enablekeyboardtruenicescroll can manage keyboard events
smoothscrolltruescroll with ease movement
sensitiverailtrueclick on rail make a scroll
enablemouselockapitruecan use mouse caption lock API (same issue on object dragging)
cursorfixedheightfalse设置光标固定高度
hidecursordelay400set the delay in microseconds to fading out scrollbars
directionlockdeadzone6dead zone in pixels for direction lock activation
nativeparentscrollingtruedetect bottom of content and let parent to scroll, as native scroll does
enablescrollonselectiontrueenable auto-scrolling of content when selection text
cursordragontouch0.3speed of selection when dragged with cursor
oneaxismousemode"auto"horizontal div scrolling starts at left side
scriptpath""drag cursor in touch / touchbehavior mode also
preventmultitouchscrollingtrueit permits horizontal scrolling with mousewheel on horizontal only content, if false (vertical-only) mousewheel don't scroll horizontally, if value is auto detects two-axis mouse
disablemutationobserverfalseforce MutationObserver disabled
enableobservertrueenable DOM changing observer, it tries to resize/hide/show when parent or content div had changed
    scrollbarid: false // set a custom ID for nicescroll bars 
scrollbaridfalseset a custom ID for nicescroll bars

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载