Mac/Safari/ Chrome hover显示scroll

2018-11-02  本文已影响257人  小宝薯
hover to scroll

一、方案

翻了Google很多方法,当时有几个参考方案

jScrollPane

二、代码思路

// app.component.html
<div class="app">
  <ul (mouseenter) ="mouseEnter($event) " (mouseleave) ="mouseLeave($event) " [class.scroll-show]="showScroll">
    <li *ngFor="let item of content; let index of index">{{item}}</li>
  </ul>
</div>

//app.component.scss
.app {
  ul, li {
    list-style: none;
  }
  ul {
    width: 300px;
    height: 400px;
    overflow: hidden;
    margin-left: 100px;
    margin-top: 100px;
    background: aliceblue;
    padding-top: 20px;
    &:hover {
      overflow-y:scroll;
    }
  }
  .scroll-show::-webkit-scrollbar
  {
      width: 5px;
      background: transparent;
  }
   .scroll-show::-webkit-scrollbar-track
  {
      width: 5px;
      background: transparent;
  }
   .scroll-show::-webkit-scrollbar-thumb
  {
      width: 5px;
      height: 30px;
      width: 5px;
      border-radius: 3.5px;
      background-color: #D8D8D8;
  }
}

// app.component.ts

export class AppComponent implements OnInit{
  title = 'app-scrollbar';
  showScroll = false;
  content = [];

  ngOnInit() {
      this.content = Array(30).fill('Lorem ipsum dolor   sit amet consectetur');
   }
  mouseEnter(e) {
    this.showScroll = true;
  }
  mouseLeave(e) {
    this.showScroll = false;

  }
}

github账号https://github.com/slwzero

上一篇 下一篇

猜你喜欢

热点阅读