To scroll to a specific div class after clicking on it using jQuery, you can use the following code:

  1. Include the GSAP library in your HTML file by adding the following script tag in the head section of your HTML file:
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.7.0/gsap.min.js"></script>
  1. Add the following JavaScript code to scroll to the desired div class:
$(document).ready(function() {
  $(".your-div-class").click(function() {
    // Get the offset top position of the target element
    var targetOffset = $(".target-div-class").offset().top;

    // Animate the scrolling
    gsap.to(window, { 
      duration: 1, 
      scrollTo: { 
        y: targetOffset 
      } 
    });
  });
});

Replace .your-div-class with the class of the div you want to click on, and .target-div-class with the class of the div you want to scroll to.

Make sure to include the jQuery library before the above code

gsapminjs i want to scroll after click on div class with jquery lang

原文地址: https://www.cveoy.top/t/topic/hM9G 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录