资讯专栏INFORMATION COLUMN

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

B0B0 / 3171人阅读

摘要:使用了很多的滚动条插件,如这次说说,支持水平滚动条,支持文本区和文档页面滚动条。,兼容所有的桌面浏览器。,兼容移动设备黑莓手机和芒果。,兼容所有触摸设备平板电脑窗口接口。,简单的安装和激活不破坏代码。

使用了很多的滚动条插件,如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库



简单使用,改变文档滚动条的风格(使用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" | , // 改变滚动条的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稳定版

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/86396.html

相关文章

  • nicescroll插件在容器宽度改变时 滚动定位如何自适应

    这几天做项目遇到了一个关于nicescroll插件在容器宽度改变时,滚动条的位置没有改变这个问题,贴出自己的解决方案,希望能对遇到和我一样问题的朋友们有所帮助。 问题描述: showImg(https://segmentfault.com/img/bV4Dxi?w=1920&h=269); 如图,这个是我nicescroll自定义样式的滚动条 showImg(https://segmentfaul...

    graf 评论0 收藏0
  • javascript功能插件大集合 前端常用插件 js常用插件

    摘要:转载来源包管理器管理着库,并提供读取和打包它们的工具。能构建更好应用的客户端包管理器。一个整合和的最佳思想,使开发者能快速方便地组织和编写前端代码的下一代包管理器。很棒的组件集合。隐秘地使用和用户数据。 转载来源:https://github.com/jobbole/aw... 包管理器管理着 javascript 库,并提供读取和打包它们的工具。•npm – npm 是 javasc...

    netmou 评论0 收藏0
  • javascript功能插件大集合 前端常用插件 js常用插件

    摘要:转载来源包管理器管理着库,并提供读取和打包它们的工具。能构建更好应用的客户端包管理器。一个整合和的最佳思想,使开发者能快速方便地组织和编写前端代码的下一代包管理器。很棒的组件集合。隐秘地使用和用户数据。 转载来源:https://github.com/jobbole/aw... 包管理器管理着 javascript 库,并提供读取和打包它们的工具。•npm – npm 是 javasc...

    Hydrogen 评论0 收藏0
  • javascript功能插件大集合,写前端亲们记得收藏

    摘要:一个专注于浏览器端和兼容的包管理器。一个整合和的最佳思想,使开发者能快速方便地组织和编写前端代码的下一代包管理器。完全插件化的工具,能在中识别和记录模式。健壮的优雅且功能丰富的模板引擎。完整的经过充分测试和记录数据结构的库。 【导读】:GitHub 上有一个 Awesome – XXX 系列的资源整理。awesome-javascript 是 sorrycc 发起维护的 JS 资源列表...

    cfanr 评论0 收藏0
  • JavaScript 资源大全中文版

    摘要:官网全新的静态包管理器。官网一个整合和官网的最佳思想,使开发者能快速方便地组织和编写前端代码的下一代包管理器。官网小巧的兼容的所见即所得的富文本编辑器。官网富文本编辑器。官网由制作,适用于每天写作的富文本编辑器。 1. 包管理器 管理着 javascript 库,并提供读取和打包它们的工具。 npm:npm 是 javascript 的包管理器。官网 cnpm:cnpm 是 由于国...

    jzman 评论0 收藏0

发表评论

0条评论

B0B0

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<