代码之家  ›  专栏  ›  技术社区  ›  Apple Orange

滚动到特定的DIV(点击)角度

  •  2
  • Apple Orange  · 技术社区  · 6 年前

    #content DIV和按钮组件。


    <div id="content">
        Loren ipsum 
    </div>
    <div (click)="toTop($event)">top</div>
    

    Topscroll.component.ts:顶部套管组件:

    export class TopscrollComponent implements OnInit { 
      constructor() { } 
    
      ngOnInit() { }
    
      toTop(event){ 
        ...
      }
    }
    
    1 回复  |  直到 6 年前
        1
  •  5
  •   Jeffrey Roosendaal SReddy    6 年前

    .scrollIntoView()

    toTop() {
      document.getElementById("content").scrollIntoView();
    }
    

    event