jQuery Effects and UI Enhancements

1. Smooth Scrolling

Smooth scrolling enhances user experience by making anchor link jumps glide smoothly instead of jumping abruptly.

<a href="#section2" class="scroll-link">Go to Section 2</a>

<div id="section2" style="margin-top: 500px;">
  <h3>Section 2</h3>
</div>

<script>
$(document).ready(function(){
  $('.scroll-link').on('click', function(e){
    e.preventDefault();
    const target = $($(this).attr('href'));
    $('html, body').animate({
      scrollTop: target.offset().top
    }, 800);
  });
});
</script>
Go to Section 2

Section 2


2. Accordion Menu

Accordion menus show or hide sections of content when clicked, perfect for FAQs or dropdowns.

<div class="accordion">
  <h3 class="accordion-header">Toggle Section</h3>
  <div class="accordion-content" style="display: none;">
    <p>This is hidden content shown on click.</p>
  </div>
</div>

<script>
$(document).ready(function(){
  $('.accordion-header').click(function(){
    $(this).next('.accordion-content').slideToggle();
  });
});
</script>

Toggle Section


3. Modal Window

Modals are dialog boxes that overlay the main content.

<button id="openModal">Open Modal</button>

<div id="myModal" style="display:none; position: fixed; top: 30%; left: 50%; transform: translateX(-50%); background: #fff; padding: 20px; border: 1px solid #ccc;">
  <p>This is a modal box.</p>
  <button id="closeModal">Close</button>
</div>

<script>
$(document).ready(function(){
  $('#openModal').click(function(){
    $('#myModal').fadeIn();
  });
  $('#closeModal').click(function(){
    $('#myModal').fadeOut();
  });
});
</script>

4. Scroll Animation (Fade In on Scroll)

Reveal elements with animation as they enter the viewport while scrolling.

<div class="scroll-box" style="margin-top: 500px; display: none;">
  <p>You scrolled to me!</p>
</div>

<script>
$(document).ready(function(){
  $(window).on('scroll', function(){
    $('.scroll-box').each(function(){
      if ($(this).offset().top <= $(window).scrollTop() + $(window).height() - 100) {
        $(this).fadeIn(1000);
      }
    });
  });
});
</script>

If you have any questions, feel free to ask. Thank you for reading!

Thankyou!