jquery插件Nicescroll 3(非常类似IOS原生的滚动条) (转)

使用了很多的滚动条插件,如Iscroll,swiper,这次说说Nicescroll

1,支持水平滚动条!

2,支持div,IFrames,文本区和文档页面滚动条。

3,兼容所有的桌面浏览器:Firefox 4 +,Chrome 5 +,Safari 4 +(win/ mac),Opera 10 +,IE 6+。

4,兼容移动设备:iPad / iPhone / iPod,Android 2.2 +,黑莓手机和playbook(WebWorks/Table OS),Windows Phone 7.5芒果。

5,兼容所有触摸设备:iPad,Android平板电脑,窗口接口。

6,兼容多输入设备(鼠标和触摸或笔):窗面,桌面Chrome,触屏笔记本;

7,兼容两头鼠:苹果魔术鼠标,苹果双轮鼠标,电脑双轮鼠标(如果浏览器支持)。

8,简单的安装和激活,不破坏代码。

9,非常时尚的滚动条,没有占领你的窗口

10,你可以定义文档滚动条的风格! !(不是所有的脚本实现此功能)

11,在所有浏览器上你可以滚动:拖动鼠标,鼠标滚轮(速度可定制),键盘导航(cursor,pagup/down,home/end )

12,滚动光滑(如现代平板电脑浏览),速度是可定制的

13,缩放功能

14,硬件加速滚动(可用)

15,动画帧支持smoth滚动和cpu-saving

16,拖动滚动模式与滚动动力(如触摸设备)

17,所有主要浏览器桌面和移动版本通过测试

18,支持触摸设备

19,支持多输入设备(与MSPointer IE10浏览器)

20,兼容其他浏览器,包括IE6,Safari在Mac和WP7芒果!

21,可定制滚动条方向

22,滚动事件

23,与jQuery代码完全集成

24,兼容jQuery UI, jQuery Touch, jQuery Mobile

引入核心文件,插件需要引入1.5.X以上版本的jquery库

<script src="http://libs.useso.com/js/jquery/1.11.1/jquery.min.js"></script>
<script src="jquery.nicescroll.js"></script>

简单使用,改变文档滚动条的风格(使用html元素)

$(document).ready(
  function() { 
    $("html").niceScroll();
  }
);

返回对象

var nice = false;
$(document).ready(
  function() { 
    nice = $("html").niceScroll();
  }
);

改变DIV光标颜色

$(document).ready(
  function() { 
    $("#thisdiv").niceScroll({cursorcolor:"#00F"});
  }
);

使用容器“wrapper”包含DIV,由两个DIV组成,前一个为vieport,后一个为内容

$(document).ready(
  function() { 
    $("#viewportdiv").niceScroll("#wrapperdiv",{cursorcolor:"#00F"});
  }
);

获取滚动对象

var nice = $("#mydiv").getNiceScroll();

隐藏滚动条

$("#mydiv").getNiceScroll().hide();

检测滚动条是否重置大小(当窗口改变大小时)

$("#mydiv").getNiceScroll().resize();

滚动到某个位置

 $("#mydiv").getNiceScroll(0).doScrollLeft(x, duration); // Scroll X Axis
 $("#mydiv").getNiceScroll(0).doScrollTop(y, duration); // Scroll Y Axis

配置参数

$("#thisdiv").niceScroll({
        cursorcolor: "#424242", // 改变滚动条颜色,使用16进制颜色值
        cursoropacitymin: 0, // 当滚动条是隐藏状态时改变透明度, 值范围 1 到 0
        cursoropacitymax: 1, // 当滚动条是显示状态时改变透明度, 值范围 1 到 0
        cursorwidth: "5px", // 滚动条的宽度,单位:像素
        cursorborder: "1px solid #fff", // CSS方式定义滚动条边框
        cursorborderradius: "5px", // 滚动条圆角(像素)
        zindex: "auto" | <number>, // 改变滚动条的DIV的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的div时,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", // DIV的水平滚动从左边开始
        cursordragontouch: false, // 使用触屏模式来实现拖拽
        oneaxismousemode: "auto", // 当只有水平滚动时可以用鼠标滚轮来滚动,如果设为false则不支持水平滚动,如果设为auto支持双轴滚动
        scriptpath: "" // 为boxmode图片自定义路径 ("" => same script path)
        preventmultitouchscrolling: true // 防止多触点事件引发滚动
    });

More

Configuration parameters
When you call "niceScroll" you can pass some parameters to custom visual aspects:

cursorcolor - change cursor color in hex, default is "#000000"
cursoropacitymin - change opacity very cursor is inactive (scrollabar "hidden" state), range from 1 to 0, default is 0 (hidden)
cursoropacitymax - change opacity very cursor is active (scrollabar "visible" state), range from 1 to 0, default is 1 (full opacity)
cursorwidth - cursor width in pixel, default is 5 (you can write "5px" too)
cursorborder - css definition for cursor border, default is "1px solid #fff"
cursorborderradius - border radius in pixel for cursor, default is "4px"
zindex - change z-index for scrollbar div, default value is 9999
scrollspeed - scrolling speed, default value is 60
mousescrollstep - scrolling speed with mouse wheel, default value is 40 (pixel)
touchbehavior - enable cursor-drag scrolling like touch devices in desktop computer (default:false)
hwacceleration - use hardware accelerated scroll when supported (default:true)
boxzoom - enable zoom for box content (default:false)
dblclickzoom - (only when boxzoom=true) zoom activated when double click on box (default:true)
gesturezoom - (only when boxzoom=true and with touch devices) zoom activated when pitch out/in on box (default:true)
grabcursorenabled, display "grab" icon for div with touchbehavior = true, (default:true)
autohidemode, how hide the scrollbar works, true=default / "cursor" = only cursor hidden / false = do not hide
background, change css for rail background, default is ""
iframeautoresize, autoresize iframe on load event (default:true)
cursorminheight, set the minimum cursor height in pixel (default:20)
preservenativescrolling, you can scroll native scrollable areas with mouse, bubbling mouse wheel event (default:true)
railoffset, you can add offset top/left for rail position (default:false)
bouncescroll, enable scroll bouncing at the end of content as mobile-like (only hw accell) (default:false)
spacebarenabled, enable page down scrolling when space bar has pressed (default:true)
railpadding, set padding for rail bar (default:{top:0,right:0,left:0,bottom:0})
disableoutline, for chrome browser, disable outline (orange hightlight) when selecting a div with nicescroll (default:true)
horizrailenabled, nicescroll can manage horizontal scroll (default:true)
railalign, alignment of vertical rail (defaul:"right")
railvalign, alignment of horizontal rail (defaul:"bottom")
enabletranslate3d, nicescroll can use css translate to scroll content (default:true)
enablemousewheel, nicescroll can manage mouse wheel events (default:true)
enablekeyboard, nicescroll can manage keyboard events (default:true)
smoothscroll, scroll with ease movement (default:true)
sensitiverail, click on rail make a scroll (default:true)
enablemouselockapi, can use mouse caption lock API (same issue on object dragging) (default:true)
cursorfixedheight, set fixed height for cursor in pixel (default:false)
hidecursordelay, set the delay in microseconds to fading out scrollbars (default:400)
directionlockdeadzone, dead zone in pixels for direction lock activation (default:6)
nativeparentscrolling , detect bottom of content and let parent to scroll, as native scroll does (default:true)
enablescrollonselection, enable auto-scrolling of content when selection text (default:true)

官网及示例:官网 示例 下载
备注:github的代码可能在手机端无法使用,建议到示例代码里面自己提取,或者:niceScroll3.6稳定版

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值