简体   繁体   English

向页面添加漂亮的滚动条

[英]Adding nice scroll bar to the page

I want to add this beautiful scroll bar implemented using Nice Scroll plugin to my web page:我想将这个使用 Nice Scroll 插件实现的漂亮滚动条添加到我的 web 页面:

my web I think the page is using an HTML structure like below and adds functionality to the scrollbar using the Nice Scroll plugin. 我的 web我认为该页面正在使用如下所示的 HTML 结构,并使用 Nice Scroll 插件向滚动条添加功能。

 $(function() { $("#ascrail2000").niceScroll(); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="ascrail2000" class="nicescroll-rails" style="width: 10px; z-index: 2999; cursor: default; position: fixed; top: 0px; height: 100%; right: 0px; opacity: 1; border-radius: 10px;"> <div style="position: relative; top: 40px; float: right; width: 3px; height: 103px; background-color: rgb(240, 159, 5); border: none; background-clip: padding-box; border-radius: 0px;"> </div> </div> <div id="ascrail2000-hr" class="nicescroll-rails" style="height: 10px; z-index: 2999; position: fixed; left: 0px; width: 100%; bottom: 0px; opacity: 1; cursor: default; display: none;"> <div style="position: relative; top: 0px; height: 10px; width: 1536px; background-color: rgb(240, 159, 5); border: none; background-clip: padding-box; border-radius: 0px;"> </div> </div>

I can't make the code working without a hand... What I'm missing?我无法让代码在没有手的情况下工作......我错过了什么?

Note: I wrote the script tag myself and I think there is a problem with it.注意:我自己写了脚本标签,我认为它有问题。

I didn't understand what did you try to do, but take a look in my example.我不明白你想做什么,但看看我的例子。 It works by setting config params and also including the cdn of nice scroll plugin.它通过设置配置参数并且还包括漂亮滚动插件的 cdn 来工作。

Add this cdn after jquery:在 jquery 之后添加这个 CDN:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.nicescroll/3.7.6/jquery.nicescroll.min.js"></script>

Nice scroll initialisation for example:不错的滚动初始化,例如:

$("#ascrail2000").niceScroll({
   cursorwidth:3,
  cursoropacitymin:0.4,
  cursorcolor:'rgb(240, 159, 5)',
  cursorborder:'none',
  cursorborderradius:4,
  autohidemode:'leave'});

plunker example笨拙的例子

For more examples please take a look at the official site: https://nicescroll.areaaperta.com/demo/更多示例请查看官方网站: https://nicescroll.areaaperta.com/demo/

Plugin is missing.插件丢失。 Added plugin in your script and it is working as expected.在您的脚本中添加了插件,它按预期工作。

 $(function() { $("#ascrail2000").niceScroll(); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.nicescroll/3.6.8-fix/jquery.nicescroll.min.js"></script> <div id="ascrail2000" class="nicescroll-rails" style="width: 10px; z-index: 2999; cursor: default; position: fixed; top: 0px; height: 100%; right: 0px; opacity: 1; border-radius: 10px;"> <div style="position: relative; top: 40px; float: right; width: 3px; height: 103px; background-color: rgb(240, 159, 5); border: none; background-clip: padding-box; border-radius: 0px;"> </div> </div> <div id="ascrail2000-hr" class="nicescroll-rails" style="height: 10px; z-index: 2999; position: fixed; left: 0px; width: 100%; bottom: 0px; opacity: 1; cursor: default; display: none;"> <div style="position: relative; top: 0px; height: 10px; width: 1536px; background-color: rgb(240, 159, 5); border: none; background-clip: padding-box; border-radius: 0px;"> </div> </div>

There's no need to use any plugin, in fact is an easy task using plain CSS.不需要使用任何插件,实际上使用普通的 CSS 是一件容易的事。 You can check this article of W3Schools where they explain how scroll bar styling works and all it's properties to be customized.您可以查看 W3Schools 的这篇文章,其中解释了滚动条样式的工作原理以及要自定义的所有属性。

https://www.w3schools.com/howto/howto_css_custom_scrollbar.asp https://www.w3schools.com/howto/howto_css_custom_scrollbar.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM