2.2、设置样式/*滚动条大小*/ .scroll::-webkit-scrollbar{ width:5px; height:10px; } /*正常情况下滑块的样式*/ .scroll::-webkit-scrollbar-thumb{ backgr._css滚动条如何调整高度自适应">
当前位置:   article > 正文

css:设置滚动条样式&高度自适应_css滚动条如何调整高度自适应

css滚动条如何调整高度自适应

一、如何出现滚动条

在样式中添加 

 overflow-y: scroll;

二、修改滚动条样式

2.1、首先在标签中定义一个class名

<div class="scroll">

2.2、设置样式

  1. /*滚动条大小*/
  2. .scroll::-webkit-scrollbar{
  3. width:5px;
  4. height:10px;
  5. }
  6. /*正常情况下滑块的样式*/
  7. .scroll::-webkit-scrollbar-thumb{
  8. background-color:rgba(0,0,0,.05);
  9. border-radius:10px;
  10. -webkit-box-shadow:inset1px1px0rgba(0,0,0,.1);
  11. }
  12. /*鼠标悬浮在该类指向的控件上时滑块的样式*/
  13. .scroll:hover::-webkit-scrollbar-thumb{
  14. background-color:rgba(0,0,0,.2);
  15. border-radius:10px;
  16. -webkit-box-shadow:inset1px1px0rgba(0,0,0,.1);
  17. }
  18. /*鼠标悬浮在滑块上时滑块的样式*/
  19. .scroll::-webkit-scrollbar-thumb:hover{
  20. background-color:rgba(0,0,0,.4);
  21. -webkit-box-shadow:inset1px1px0rgba(0,0,0,.1);
  22. }
  23. /*正常时候的主干部分*/
  24. .scroll::-webkit-scrollbar-track{
  25. border-radius:10px;
  26. -webkit-box-shadow:inset006pxrgba(0,0,0,0);
  27. background-color:white;
  28. }
  29. /*鼠标悬浮在滚动条上的主干部分*/
  30. .scroll::-webkit-scrollbar-track:hover{
  31. -webkit-box-shadow:inset006pxrgba(0,0,0,.4);
  32. background-color:rgba(0,0,0,.01);
  33. }

2.3、没有了,

三、PC高度自适应(和上面的配合使用)

3.1、标签

<div class="scroll" style="overflow-y: scroll;" :style="{ height: screenHeight + 'px' }">

3.2、vue中data

  1. data() {
  2. return {
  3. topHeight: 200, //导航栏或者顶部的高度
  4. screenHeight: document.body.clientHeight - this.topHeight,
  5. }
  6. },

3.3、

  1. watch: {
  2. screenHeight (val) {
  3. // 为了避免频繁触发resize函数导致页面卡顿,使用定时器
  4. if (!this.timer) {
  5. // 一旦监听到的screenWidth值改变,就将其重新赋给data里的screenWidth
  6. this.screenHeight = val;
  7. this.timer = true;
  8. let that = this;
  9. setTimeout(function () {
  10. // 打印screenWidth变化的值
  11. console.log(that.screenHeight);
  12. that.timer = false
  13. }, 400)
  14. }
  15. }
  16. },

3.4、

  1. mounted () {
  2. const that = this;
  3. window.onresize = () => {
  4. return (() => {
  5. // 可以限制最小高度
  6. // if (document.body.clientHeight - 240 < 450) {
  7. // return
  8. // }
  9. window.screenHeight = document.body.clientHeight- this.topHeight;
  10. that.screenHeight = window.screenHeight;
  11. })()
  12. }
  13. },

3.5、打开PC浏览器测试

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/280083?site
推荐阅读
相关标签
  

闽ICP备14008679号