seleccion-articulos.component.ts 1.24 KB
import { Component, OnInit } from "@angular/core";

@Component({
  selector: "app-seleccion-articulos",
  templateUrl: "./seleccion-articulos.component.html",
  styleUrls: ["./seleccion-articulos.component.scss"]
})
export class SeleccionArticulosComponent implements OnInit {
  timeoutHandler: any;
  categorias = [
    { id: 1, selected: false },
    { id: 2, selected: false },
    { id: 3, selected: false },
    { id: 4, selected: false },
    { id: 5, selected: false },
    { id: 6, selected: false }
  ];

  constructor() {}

  ngOnInit() {}

  selectCategoria(index: number) {
    this.categorias.forEach((categoria, i) => {
      categoria.selected = index === i ? true : false;
    });
  }

  mouseup() {
    if (!this.timeoutHandler) return;
    clearInterval(this.timeoutHandler);
  }

  scrollY(el: HTMLElement, value) {
    el.scroll({ behavior: "smooth", top: value + el.scrollTop });
    this.timeoutHandler = setInterval(() => {
      el.scroll({ behavior: "smooth", top: value + el.scrollTop });
    }, 500);
  }

  scrollX(el: HTMLElement, value) {
    el.scroll({ behavior: "smooth", left: value + el.scrollLeft });
    this.timeoutHandler = setInterval(() => {
      el.scroll({ behavior: "smooth", left: value + el.scrollLeft });
    }, 500);
  }
}