Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
Cuando la URL cambia al desplazarse a un cierto hash, agregue una clase a un div

El hash de mi URL cambia al desplazarse desde

  • www.website.com#section--1
  • www.website.com#section--2
  • www.website.com#section--3

y así. Es un efecto de desplazamiento de página completa.

Lo que quiero hacer es agregar la clase .draw-shirt al div #shirt cuando la URL cambia al desplazarse a #section--2.

Probé este código:

 $(document).ready(function () { if (window.location.href.indexOf("emotion--2") > -1) { $('#shirt').addClass('draw-shirt'); } }); $(window).scroll(function () { function locationHashChanged() { if(window.location.href.indexOf("emotion--2") > -1) { $('#shirt').addClass('draw-shirt'); } } });

Funciona, si la URL es www.website.com#section--2 en la carga pero no en el desplazamiento.

El código

 function isScrolledIntoView(elem) {...etc...

no funciona aquí debido al efecto de desplazamiento de página completa.

Gracias por ayudar.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Creo que podría usar el evento hashchange nativo del objeto de ventana.

 window.addEventListener('hashchange', function() { if (location.hash === '#emotion--2') { // your code to add class } });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!