Jquery自定义滚动条插件

 

下载地址:http://files.cnblogs.com/files/LoveOrHate/jquery.nicescroll.min.js

 

 <script src="jquery.nicescroll.js"></script>

 

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

 

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

 

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

 

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

 

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

 

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

 

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

 

入门篇的一些插件

 

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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Layui框架自带的滚动条样式比较简单,如果需要自定义滚动条样式,可以考虑使用第三方插件。以下是一个使用mCustomScrollbar插件自定义滚动条样式的示例: 1. 引入mCustomScrollbar插件的CSS和JS文件 ```html <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/malihu-custom-scrollbar-plugin/3.1.5/jquery.mCustomScrollbar.min.css" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/malihu-custom-scrollbar-plugin/3.1.5/jquery.mCustomScrollbar.concat.min.js"></script> ``` 2. 在需要自定义滚动条的元素上添加class属性为“custom-scrollbar” ```html <div class="custom-scrollbar"> <!-- 这里是需要滚动的内容 --> </div> ``` 3. 在JavaScript中初始化mCustomScrollbar插件 ```javascript $(document).ready(function(){ $(".custom-scrollbar").mCustomScrollbar({ theme: "dark", // 滚动条主题,可选值有:dark、light、minimal、rounded、3d、3d-thick、inset、inset-dark、inset-2、inset-2-dark、rounded-dots、rounded-dots-dark、rounded-dark、rounded-light、rounded-flat、rounded-dots-blue scrollInertia: 300, // 滚动惯性 axis:"y", // 滚动方向,可选值有:y、x、yx advanced:{ autoExpandHorizontalScroll: true } // 水平滚动条自动扩展 }); }); ``` 4. 根据需要自定义滚动条的样式 ```css /* 滚动条轨道样式 */ .mCSB_scrollTools { background-color: #f0f0f0; border-radius: 5px; } /* 滚动条样式 */ .mCSB_dragger .mCSB_dragger_bar { background-color: #999; border-radius: 5px; } /* 鼠标悬停在滚动条上的样式 */ .mCSB_dragger:hover .mCSB_dragger_bar { background-color: #666; } ``` 通过以上步骤,就可以自定义Layui框架中的滚动条样式了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值