Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
Función de activación cuando el elemento está visible en la pantalla (ventana gráfica)

jQuery hace que aparezca el complemento o el punto de referencia para detectar si el elemento está visible o no en la ventana gráfica. Investigué un poco, no puedo encontrar y me pregunto si Angular2 tiene un complemento similar. Si aún no, ¿cuál es la mejor manera de hacer algo así?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Así es como lo hago:

sync-dom.utils.ts

 static isInViewPort(rect: ClientRect, threshold = 0) { return rect && rect.height && rect.top + rect.height + threshold >= 0 && rect.left + rect.width + threshold >= 0 && rect.bottom - rect.height - threshold <= SyncDomUtils.windowHeight && rect.right - rect.width - threshold <= SyncDomUtils.windowWidth; }

dom.utils.ts

 async isInViewPort(rect: ClientRect) { return SyncDomUtils.isInViewPort(rect); }

y en tu componente haces:

 async isInViewPort() { // you have to import the Renderer and ElementRef from angular/core this.boundingRect = await this.domElementUtils .invokeElementMethod(this.renderer, this.el.nativeElement, 'getBoundingClientRect'); return await this.domUtils.isInViewPort(this.boundingRect); }

y use esa función como this.isInViewPort() y devolverá un valor booleano

este es el método del elemento de invokeElementMethod que tengo en dom-element.utils.ts

 async invokeElementMethod<T extends keyof HTMLElement>(renderer: Renderer, element: any, methodName: T, args?: any[]) { return await renderer.invokeElementMethod(element, methodName, args) as any; }
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda