一定要放在 $(document).ready 中進(jìn)行初始化朝聋!
// 1. 最簡(jiǎn)單的用法如下:
$(document).ready(function() {
$("html").niceScroll();
});
// 2. Instance with object returned:
var nice = false;
$(document).ready(function() {
nice = $("html").niceScroll();
});
// 3. 設(shè)置DIV并更改光標(biāo)顏色:
$(document).ready(function() {
$("#thisdiv").niceScroll({cursorcolor:"#00F"});
});
// 4. DIV with "wrapper", formed by two divs, the first is the vieport, the latter is the content:
$(document).ready(function() {
$("#viewportdiv").niceScroll("#wrapperdiv",{cursorcolor:"#00F"});
});
// 5. 獲取nicescroll對(duì)象:
var nice = $("#mydiv").getNiceScroll();
// 6. 隱藏滾動(dòng)條:
$("#mydiv").getNiceScroll().hide();
// 7. 檢查滾動(dòng)條大屑洹(內(nèi)容或位置發(fā)生變化時(shí)):
$("#mydiv").getNiceScroll().resize();
// 8. 滾動(dòng)到某個(gè)位置:
$("#mydiv").getNiceScroll(0).doScrollLeft(x, duration); // Scroll X Axis
$("#mydiv").getNiceScroll(0).doScrollTop(y, duration); // Scroll Y Axis
當(dāng)您調(diào)用“niceScroll”時(shí)结序,您可以將一些參數(shù)重新配置傳遞:
$("#thisdiv").niceScroll({
cursorcolor: "#424242", // 改變滾動(dòng)條顏色,使用16進(jìn)制顏色值
cursoropacitymin: 0, // 當(dāng)滾動(dòng)條是隱藏狀態(tài)時(shí)改變透明度, 值范圍 1 到 0
cursoropacitymax: 1, // 當(dāng)滾動(dòng)條是顯示狀態(tài)時(shí)改變透明度, 值范圍 1 到 0
cursorwidth: "5px", // 滾動(dòng)條的寬度刚盈,單位:便素
cursorborder: "1px solid #fff", // CSS方式定義滾動(dòng)條邊框
cursorborderradius: "5px", // 滾動(dòng)條圓角(像素)
zindex: "auto" | <number>, // 改變滾動(dòng)條的DIV的z-index值
scrollspeed: 60, // 滾動(dòng)速度
mousescrollstep: 40, // 鼠標(biāo)滾輪的滾動(dòng)速度 (像素)
touchbehavior: false, // 激活拖拽滾動(dòng)
hwacceleration: true, // 激活硬件加速
boxzoom: false, // 激活放大box的內(nèi)容
dblclickzoom: true, // (僅當(dāng) boxzoom=true時(shí)有效)雙擊box時(shí)放大
gesturezoom: true, // (僅 boxzoom=true 和觸屏設(shè)備時(shí)有效) 激活變焦當(dāng)out/in(兩個(gè)手指外張或收縮)
grabcursorenabled: true // (僅當(dāng) touchbehavior=true) 顯示“抓住”圖標(biāo)display "grab" icon
autohidemode: true, // 隱藏滾動(dòng)條的方式, 可用的值:
true | // 無(wú)滾動(dòng)時(shí)隱藏
"cursor" | // 隱藏
false | // 不隱藏,
"leave" | // 僅在指針離開(kāi)內(nèi)容時(shí)隱藏
"hidden" | // 一直隱藏
"scroll", // 僅在滾動(dòng)時(shí)顯示
background: "", // 軌道的背景顏色
iframeautoresize: true, // 在加載事件時(shí)自動(dòng)重置iframe大小
cursorminheight: 32, // 設(shè)置滾動(dòng)條的最小高度 (像素)
preservenativescrolling: true, // 你可以用鼠標(biāo)滾動(dòng)可滾動(dòng)區(qū)域的滾動(dòng)條和增加鼠標(biāo)滾輪事件
railoffset: false, // 可以使用top/left來(lái)修正位置
bouncescroll: false, // (only hw accell) 啟用滾動(dòng)跳躍的內(nèi)容移動(dòng)
spacebarenabled: true, // 當(dāng)按下空格時(shí)使頁(yè)面向下滾動(dòng)
railpadding: { top: 0, right: 0, left: 0, bottom: 0 }, // 設(shè)置軌道的內(nèi)間距
disableoutline: true, // 當(dāng)選中一個(gè)使用nicescroll的div時(shí)仪糖,chrome瀏覽器中禁用outline
horizrailenabled: true, // nicescroll可以管理水平滾動(dòng)
railalign: right, // 對(duì)齊垂直軌道
railvalign: bottom, // 對(duì)齊水平軌道
enabletranslate3d: true, // nicescroll 可以使用CSS變型來(lái)滾動(dòng)內(nèi)容
enablemousewheel: true, // nicescroll可以管理鼠標(biāo)滾輪事件
enablekeyboard: true, // nicescroll可以管理鍵盤(pán)事件
smoothscroll: true, // ease動(dòng)畫(huà)滾動(dòng)
sensitiverail: true, // 單擊軌道產(chǎn)生滾動(dòng)
enablemouselockapi: true, // 可以用鼠標(biāo)鎖定API標(biāo)題 (類(lèi)似對(duì)象拖動(dòng))
cursorfixedheight: false, // 修正光標(biāo)的高度(像素)
hidecursordelay: 400, // 設(shè)置滾動(dòng)條淡出的延遲時(shí)間(毫秒)
directionlockdeadzone: 6, // 設(shè)定死區(qū),為激活方向鎖定(像素)
nativeparentscrolling: true, // 檢測(cè)內(nèi)容底部便于讓父級(jí)滾動(dòng)
enablescrollonselection: true, // 當(dāng)選擇文本時(shí)激活內(nèi)容自動(dòng)滾動(dòng)
cursordragspeed: 0.3, // 設(shè)置拖拽的速度
rtlmode: "auto", // DIV的水平滾動(dòng)從左邊開(kāi)始
cursordragontouch: false, // 使用觸屏模式來(lái)實(shí)現(xiàn)拖拽
oneaxismousemode: "auto", // 當(dāng)只有水平滾動(dòng)時(shí)可以用鼠標(biāo)滾輪來(lái)滾動(dòng)忙上,如果設(shè)為false則不支持水平滾動(dòng)拷呆,如果設(shè)為auto支持雙軸滾動(dòng)
scriptpath: "" // 為boxmode圖片自定義路徑 ("" => same script path)
preventmultitouchscrolling: true // 防止多觸點(diǎn)事件引發(fā)滾動(dòng)
});
官網(wǎng)地址:http://www.areaaperta.com/nicescroll/