JavaScript自定义浏览器滚动条兼容IE、 火狐和chrome

今天为大家分享一下我自己制作的浏览器滚动条,我们知道用css来自定义滚动条也是挺好的方式,css虽然能够改变chrome浏览器的滚动条样式可以自定义,css也能够改变IE浏览器滚动条的颜色。但是css只能是改变IE浏览器的颜色,而且CSS不能做到改变火狐浏览器的样式和颜色。所以只能是通过JavaScript来实现了。也有插件可以做到。我分享一下我自己使用原生JavaScript实现的思路。先上个图看下效果

JavaScript实现的思路就是模拟浏览器自身滚动条。我制作的思路是先将整个文档放在一个容器里面,然后通过改变容器里面的div的top值来实现滚动效果布局如下:

rush:xhtml;">
Box">
mputing,such as one second to complete the current supercomputer computing tasks for several years,but so far did not create a true sense of the quantum computer,one of the very important reason is that,The state of particles used in quantum computation is not stable,and any electromagnetic or physical interference can easily disrupt its work. The state of the Mayola fermion is very stable,which makes it a perfect choice for making quantum computers. Six months ago in the laboratory of Shanghai Jiaotong University,Jia Jinfeng successfully captured it. Speaking of the scene,Jia Jinfeng said: "In fact,I started to hear the Mayolana fermions,I think this thing may not be done 20 years out. Using a special material preparation method,Jia Jinfeng's research team has grown topological insulators on the superconductors with thickness of 5 nanometers. The topological superconductor materials are prepared and finally the Mayolana fermions are found at the interface of the topological superconductors. The mysterIoUs particles were captured 80 years,but also let Jia Jinfeng more firm with its confidence in the manufacture of quantum computers. Speaking of the future of the plan,Jia Jinfeng said: "I hope to within a few years to do the topological quantum bit!" (Before) the world has not,so if we cut into this from the point,we are the same with the world The starting line,for our country,this is able to catch up with the footsteps of quantum computing,a starting point.

先定义滑块和滑动条,然后在定义一个内容的盒子,布局很简单,body的 overflow设置成hidden隐藏认滚动条。

实现主要思路就是:滑块移动距离/滑块滚动范围=内容滚动距离/内容可滚动高度;滑块移动距离就是鼠标按下后拖动的距离,

内容可滚动高度就是内容总高度减去可视区域高度。另外,滚动条的总高度就是可视区域的高度,滑块的高度=可视区域的高度/内容的总高度*可视区域的高度。最后就是判断浏览器是否是火狐。

rush:xhtml;">

以上就是我自己实现的整个过程,其中也存在不少BUG,比如没有解决浏览器缩放时候的问题。感谢大家的阅读,如有指正的地方欢迎大家指正纠错

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持编程之家!

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...