How to use jQuery's scroll bar plug-in Nicescroll?
Nicescroll scroll bar plug-in is a very powerful scroll bar plug-in based on jQuery. It does not require additional css and is compatible with almost all browsers. IE6+ only requires a piece of code to implement, is very intrusive, the style is fully customizable, supports touch events, and can be used on touch screens.
Introduce the core file, and the plug-in needs to introduce the jquery library of version 1.5.X or above
The simplest usage is as follows:
$(document).ready( function() { $("html").niceScroll(); } );
Note: Must be initialized in $(document).ready!
Hide scroll bar
$("#myp").getNiceScroll().hide();
Detect whether the scroll bar is resized (when the window changes size)
$("#myp").getNiceScroll().resize();
Scroll to a certain position
$("#myp").getNiceScroll(0).doScrollLeft(x, duration); // Scroll X Axis $("#myp").getNiceScroll(0).doScrollTop(y, duration); // Scroll Y Axis
Various parameters can be added
$(document).ready( function() { $("#thisp").niceScroll({cursorcolor:"#00F"}); } );
Configuration parameter table
$("#thisp").niceScroll({ cursorcolor: "#424242", // 改变滚动条颜色,使用16进制颜色值 cursoropacitymin: 0, // 当滚动条是隐藏状态时改变透明度, 值范围 1 到 0 cursoropacitymax: 1, // 当滚动条是显示状态时改变透明度, 值范围 1 到 0 cursorwidth: "5px", // 滚动条的宽度,单位:便素 cursorborder: "1px solid #fff", // CSS方式定义滚动条边框 cursorborderradius: "5px", // 滚动条圆角(像素) zindex: "auto" | <number>, // 改变滚动条的p的z-index值 scrollspeed: 60, // 滚动速度 mousescrollstep: 40, // 鼠标滚轮的滚动速度 (像素) touchbehavior: false, // 激活拖拽滚动 hwacceleration: true, // 激活硬件加速 boxzoom: false, // 激活放大box的内容 dblclickzoom: true, // (仅当 boxzoom=true时有效)双击box时放大 gesturezoom: true, // (仅 boxzoom=true 和触屏设备时有效) 激活变焦当out/in(两个手指外张或收缩) grabcursorenabled: true // (仅当 touchbehavior=true) 显示“抓住”图标display "grab" icon autohidemode: true, // 隐藏滚动条的方式, 可用的值: true | // 无滚动时隐藏 "cursor" | // 隐藏 false | // 不隐藏, "leave" | // 仅在指针离开内容时隐藏 "hidden" | // 一直隐藏 "scroll", // 仅在滚动时显示 background: "", // 轨道的背景颜色 iframeautoresize: true, // 在加载事件时自动重置iframe大小 cursorminheight: 32, // 设置滚动条的最小高度 (像素) preservenativescrolling: true, // 你可以用鼠标滚动可滚动区域的滚动条和增加鼠标滚轮事件 railoffset: false, // 可以使用top/left来修正位置 bouncescroll: false, // (only hw accell) 启用滚动跳跃的内容移动 spacebarenabled: true, // 当按下空格时使页面向下滚动 railpadding: { top: 0, right: 0, left: 0, bottom: 0 }, // 设置轨道的内间距 disableoutline: true, // 当选中一个使用nicescroll的p时,chrome浏览器中禁用outline horizrailenabled: true, // nicescroll可以管理水平滚动 railalign: right, // 对齐垂直轨道 railvalign: bottom, // 对齐水平轨道 enabletranslate3d: true, // nicescroll 可以使用CSS变型来滚动内容 enablemousewheel: true, // nicescroll可以管理鼠标滚轮事件 enablekeyboard: true, // nicescroll可以管理键盘事件 smoothscroll: true, // ease动画滚动 sensitiverail: true, // 单击轨道产生滚动 enablemouselockapi: true, // 可以用鼠标锁定API标题 (类似对象拖动) cursorfixedheight: false, // 修正光标的高度(像素) hidecursordelay: 400, // 设置滚动条淡出的延迟时间(毫秒) directionlockdeadzone: 6, // 设定死区,为激活方向锁定(像素) nativeparentscrolling: true, // 检测内容底部便于让父级滚动 enablescrollonselection: true, // 当选择文本时激活内容自动滚动 cursordragspeed: 0.3, // 设置拖拽的速度 rtlmode: "auto", // p的水平滚动从左边开始 cursordragontouch: false, // 使用触屏模式来实现拖拽 oneaxismousemode: "auto", // 当只有水平滚动时可以用鼠标滚轮来滚动,如果设为false则不支持水平滚动,如果设为auto支持双轴滚动 scriptpath: "" // 为boxmode图片自定义路径 ("" => same script path) preventmultitouchscrolling: true // 防止多触点事件引发滚动 });
Also note: When using multiple nicescroll plug-ins on the same page, hide the used nicescroll in time When loading an object, you need to show it first and then resize it.
When the plug-in is placed in a container with absolute float and the top value is set, there will be a problem with the top of the plug-in. The solution is to use the railoffset attribute of the plug-in:
railoffset, you can add offset top/left for rail position (default:false)
The above is the detailed content of How to use jQuery's scroll bar plug-in Nicescroll?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

jQuery is a fast, small, feature-rich JavaScript library widely used in front-end development. Since its release in 2006, jQuery has become one of the tools of choice for many developers, but in practical applications, it also has some advantages and disadvantages. This article will deeply analyze the advantages and disadvantages of jQuery and illustrate it with specific code examples. Advantages: 1. Concise syntax jQuery's syntax design is concise and clear, which can greatly improve the readability and writing efficiency of the code. for example,

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute
