Horizontal Scroll using buttons on angular2

后端 未结 2 1503
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-29 09:36

So I have this app in angular2 where I need to scroll a component horizontally but with buttons right and left. So I need a function for each button that scroll to right or

2条回答
  •  感情败类
    2020-12-29 09:50

    Consider the following solution

    In .html

    WIDGET
    WIDGET
    WIDGET
    WIDGET
    WIDGET
    WIDGET

    In .scss

    .custom-slider-main{
        display: flex;
        overflow: hidden;    
        scroll-behavior: smooth;
    }
    

    In .ts

    @ViewChild('widgetsContent') widgetsContent: ElementRef;
    

    And On click of left/right button use the following functions

    scrollLeft(){
        this.widgetsContent.nativeElement.scrollLeft -= 150;
      }
    
      scrollRight(){
        this.widgetsContent.nativeElement.scrollLeft += 150;
      }
    

提交回复
热议问题