前言

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

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

nicescroll是一个jquery的插件,需要先包含jquery,再使用这框架,NiceScroller可用于jQuery1.x/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. Simple mode, it styles document scrollbar:【直接替换传统的scroll】
$(function() {  $("body").niceScroll();
});// 2. Instance with object returned:【获取body中替换的NiceScroll对象】
var nice = false;
$(function() {  nice = $("body").niceScroll();
});// 3. Style a DIV and change cursor color:【改变div的style】
$(function() {  $("#thisdiv").niceScroll({cursorcolor:"#00F"});
});// 4. DIV with "wrapper", formed by two divs, the first is the vieport, the latter is the content:【div嵌套时的用法,外层的叫viewport,内层的是warpper】
$(function() {$("#viewportdiv").niceScroll("#wrapperdiv",{cursorcolor:"#00F"});
});// 5. Get nicescroll object:【获取NiceScroll对象】
var nice = $("#mydiv").getNiceScroll();// 6. Hide scrollbars:【隐藏Scrollbars】
$("#mydiv").getNiceScroll().hide();// 7. Check for scrollbars resize (when content or position have changed):【当内容和位置发生改变时,就要使用resize这个函数了】
$("#mydiv").getNiceScroll().resize();// 8. Scrolling to a position:【获取sroll的位置,x轴和y轴】
$("#mydiv").getNiceScroll(0).doScrollLeft(x, duration); // Scroll X Axis
$("#mydiv").getNiceScroll(0).doScrollTop(y, duration); // Scroll Y Axis

NiceScroll相关参数

$("#thisdiv").niceScroll({cursorcolor: "#424242", // change cursor color in hexcursoropacitymin: 0, // change opacity when cursor is inactive (scrollabar "hidden" state), range from 1 to 0cursoropacitymax: 1, // change opacity when cursor is active (scrollabar "visible" state), range from 1 to 0cursorwidth: "5px", // cursor width in pixel (you can also write "5px")cursorborder: "1px solid #fff", // css definition for cursor bordercursorborderradius: "5px", // border radius in pixel for cursorzindex: "auto" | [number], // change z-index for scrollbar divscrollspeed: 60, // scrolling speedmousescrollstep: 40, // scrolling speed with mouse wheel (pixel)touchbehavior: false, // DEPRECATED!! use "emulatetouch"emulatetouch: false, // enable cursor-drag scrolling like touch devices in desktop computerhwacceleration: true, // use hardware accelerated scroll when supportedboxzoom: false, // enable zoom for box contentdblclickzoom: true, // (only when boxzoom=true) zoom activated when double click on boxgesturezoom: true, // (only when boxzoom=true and with touch devices) zoom activated when pinch out/in on boxgrabcursorenabled: true // (only when touchbehavior=true) display "grab" iconautohidemode: true, // how hide the scrollbar works, possible values: true | // hide when no scrolling"cursor" | // only cursor hiddenfalse | // do not hide,"leave" | // hide only if pointer leaves content"hidden" | // hide always"scroll", // show only on scroll          background: "", // change css for rail backgroundiframeautoresize: true, // autoresize iframe on load eventcursorminheight: 32, // set the minimum cursor height (pixel)preservenativescrolling: true, // you can scroll native scrollable areas with mouse, bubbling mouse wheel eventrailoffset: false, // you can add offset top/left for rail positionbouncescroll: false, // (only hw accell) enable scroll bouncing at the end of content as mobile-like spacebarenabled: true, // enable page down scrolling when space bar has pressedrailpadding: { top: 0, right: 0, left: 0, bottom: 0 }, // set padding for rail bardisableoutline: true, // for chrome browser, disable outline (orange highlight) when selecting a div with nicescrollhorizrailenabled: true, // nicescroll can manage horizontal scrollrailalign: right, // alignment of vertical railrailvalign: bottom, // alignment of horizontal railenabletranslate3d: true, // nicescroll can use css translate to scroll contentenablemousewheel: true, // nicescroll can manage mouse wheel eventsenablekeyboard: true, // nicescroll can manage keyboard eventssmoothscroll: true, // scroll with ease movementsensitiverail: true, // click on rail make a scrollenablemouselockapi: true, // can use mouse caption lock API (same issue on object dragging)cursorfixedheight: false, // set fixed height for cursor in pixelhidecursordelay: 400, // set the delay in microseconds to fading out scrollbarsdirectionlockdeadzone: 6, // dead zone in pixels for direction lock activationnativeparentscrolling: true, // detect bottom of content and let parent to scroll, as native scroll doesenablescrollonselection: true, // enable auto-scrolling of content when selection textcursordragspeed: 0.3, // speed of selection when dragged with cursorrtlmode: "auto", // horizontal div scrolling starts at left sidecursordragontouch: false, // drag cursor in touch / touchbehavior mode alsooneaxismousemode: "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 mousescriptpath: "" // define custom path for boxmode icons ("" => same script path)preventmultitouchscrolling: true // prevent scrolling on multitouch eventsdisablemutationobserver: false // force MutationObserver disabled,enableobserver: true // enable DOM changing observer, it tries to resize/hide/show when parent or content div had changedscrollbarid: false // set a custom ID for nicescroll bars
});

此处用个表简单解释下:

property value description
cursorcolor "#424242" 改变光标颜色(十六进制)
cursoropacitymin 0 当光标是无效状态时改变其透明度,范围从1到0
cursoropacitymax 1 当光标是有效状态时改变其透明度,范围从1到0
cursorwidth "5px" 光标的宽度为5像素
cursorborder "1px solid #fff" 使用css定义光标包边
cursorborderradius "5px" 光标的包边半径(改包边为圆弧)
zindex "auto" | [number] 改变光标div的z-index
scrollspeed 60 光标速率
mousescrollstep 40 用滚轮滚动的光标速率
touchbehavior false 不要使用,改用emulatetouch
emulatetouch false 开启cursor-darg功能(像触屏滚动的那个效果)
hwacceleration true hw是hardware,使用硬件加数功能
boxzoom false 开启内容放缩功能
dbclickzoom true 当boxzoom为true时使用,当鼠标双击时zoom为激活状态
gesturezoom true 当boxzoom为true、touch devices为true时使用
grabcursorenabled true 当touchbehavior=true时生效,展示"grab"图标
autohidemode true
"cursor"
false
"leave"
"hidden"
"scroll"
当不滚动时,scrolllbar被隐藏;
仅光标被隐藏;
不隐藏;
仅隐藏上下箭头;
隐藏;
只有在滚的时候显示
background "" 使用css定义background
iframeautoresize true auto resize
cursorminheight 32 设置光标最小高度
preservenatviescrolling true 使用原始的滚轮
radiloffset false 为rail postiont添加top/left的偏移
bouncescroll false (only hw accell) enable scroll bouncing at the end of content as mobile-like
spacebarenabled true enable page down scrolling when space bar has pressed
railpadding {top: 0, right: 0, left 0, bottom: 0} 给rail bar设置padding
disableoutline true for chrome browser, disable outline (orange highlight) when selecting a div with nicescroll
horizrailenabled true nicescroll can manage horizontal scroll
railalign right 垂直滑轨的位置
railvalign bottom 水平滑轨的位置
enabletranslate3d true nicescroll can use css translate to scroll content
enablemousewheel true nicescroll can manage mouse wheel events
enablekeyboard true nicescroll can manage keyboard events
smoothscroll true scroll with ease movement
sensitiverail true click on rail make a scroll
enablemouselockapi true can use mouse caption lock API (same issue on object dragging)
cursorfixedheight false 设置光标固定高度
hidecursordelay 400 set the delay in microseconds to fading out scrollbars
directionlockdeadzone 6 dead zone in pixels for direction lock activation
nativeparentscrolling true detect bottom of content and let parent to scroll, as native scroll does
enablescrollonselection true enable auto-scrolling of content when selection text
cursordragontouch 0.3 speed of selection when dragged with cursor
oneaxismousemode "auto" horizontal div scrolling starts at left side
scriptpath "" drag cursor in touch / touchbehavior mode also
preventmultitouchscrolling true 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
disablemutationobserver false force MutationObserver disabled
enableobserver true enable 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 
scrollbarid false set a custom ID for nicescroll bars

NiceScroll文档阅读笔记-NiceScroll(3.7.6)基本使用相关推荐

  1. Qt文档阅读笔记-共享库的创建与调用

    使用共享库的符号 这个符号可以作用在变量.类.函数中,并且这些都可以被调用端使用. 在编译共享库中,需要使用export符号.在使用端调用的时候使用import符号. 这里是本人从文档中记录的笔记,大 ...

  2. Qt文档阅读笔记-加载HeightMap(高度图)构造3D地形图

    Qt文档阅读笔记-加载HeightMap(高度图)构造3D地形图 QHeightMapSurfaceDataProxy:是Q3DSurface的一个基本代理类. 他是专门加载高度图. 高度图是没有X, ...

  3. Qt文档阅读笔记-Rotations Example相关

    Rotations Example文档阅读笔记 使用这种方式,对y轴和z轴进行旋转. QQuaternion yRotation = QQuaternion::fromAxisAndAngle(0.0 ...

  4. FreeRTOS官方指导文档阅读笔记

    FreeRTOS官方指导文档阅读笔记 基于 161204_Mastering_the_FreeRTOS_Real_Time_Kernel-A_Hands-On_Tutorial_Guide.pdf,可 ...

  5. Blockly学习之文档阅读笔记

    文档阅读来源--谷歌官网介绍: https://developers.google.com/blockly/guides/overview 概述 一个用于Web.Android.iOS的可视化代码编辑 ...

  6. Leaflet文档阅读笔记-Quick Start Guide笔记

    目录 网络加载JS和CSS 初始化地图 在地图上做标记 在地图上点击事件获得坐标 个人对这篇文档的体会 网络加载JS和CSS 先要加载css,然后在加载js <link rel="st ...

  7. Qt文档阅读笔记-QWebEngineView及QML WebEngineView

    这里主要是最近有给Java Web项目及Qt项目需要混合,自己搞的QtWebEngine没有问题,而用了项目里面的,就有问题,在此阅读下官方资料,看看能不能解决这样莫名其妙的问题,在此记录下本次的阅读 ...

  8. Qt文档阅读笔记-moc工具使用及其理论(moc工具如何添加到makefile中)

    moc(Meta-Object Compiler):用于处理Qt中关于C++的扩展. moc工具读取C++头文件,看看这个头文件里面的类是不是包含Q_OBJECT宏,它会将这个头文件,转换为带有met ...

  9. Java文档阅读笔记-EJB Tutorial

    目录 Introduction to EJB What is EJB Introduction to EJB EJB(Enterprise Java Bean)Java企业组建:用于开发分布式.健全. ...

最新文章

  1. JAVA基础 (二)反射 深入解析反射机制
  2. 可以查python题的_python练习题 -股票查询
  3. mysql zrm 配置_利用MySQL-zrm来备份和恢复MySQL数据库方法详解
  4. echarts指针进度条刻度调整_指针式流量开关
  5. 几种流行的JS框架的选择
  6. master分支删除文件_Git分支基础简介;创建分支;合并分支;删除分支;
  7. wpf绑定treeview 带查找_如何查找,修复和避免C#.NET中内存泄漏的8个最佳实践
  8. PHP设计模式之工厂模式
  9. 【Liunx】Linux 文件与目录管理
  10. 【论文阅读】Graph Networks for Multiple Object Tracking
  11. 12-matlab简单读excel
  12. 如何正确添加水印保护自己的版权?
  13. Javashop B2B2C 系统之社区团购商城
  14. 尚学堂马士兵老师oracle笔记
  15. Linux 之十五 Kernel 仓库、Kernel 协作方式、订阅邮件列表、提交 PATCH
  16. 用python一键生成动画(上)
  17. JavaScript中的let声明
  18. warning C4996的分析
  19. Delphi 2010的好消息
  20. 基础环境搭建——基于Spark平台的协同过滤实时电影推荐系统项目系列博客(五)

热门文章

  1. 尝试加载 Oracle 客户端库时引发 BadImageFormatException。如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行,将出现此问题。...
  2. 深度剖析WinPcap之(九)——数据包的发送过程(8)
  3. Java牛角尖【003】:类初始化时的执行顺序
  4. 在批评数据湖的时候,你有没有想过,它并不是取代数据仓库的
  5. 盘点 GitHub 上那些沙雕项目
  6. 构思新巧的173dmba飞鸽
  7. FreeEIM通讯软件平均需要5分钟才能
  8. 2011年想要惊喜的5z20
  9. SOCKET入门最简单的程序啊
  10. 大型网站的Google排名策略