Good day. There is a script for scrolling up the page to the given id div. How to make so that at the end of scrolling the given div is highlighted for a few seconds with a frame. Please tell me the solution.

$(document).ready(function(){ $('a[href^="#"]').on('click',function (e) { e.preventDefault(); var target = this.hash; var $target = $(target); $('html, body').animate({ 'scrollTop': $target.offset().top }, 1000, 'swing'); }); }); 
  • one
    animate has a callback for when the animation is over. There you can use the second animate and css add + remove the frame. - br3t
  • Please tell me where to write in more detail, otherwise I’m not booming in java. I would be very grateful for the help. - John Dick

1 answer 1

Good afternoon! In .animate (), the fourth parameter is a function that can be executed after the animation is executed.

 $(document).ready(function(){ $('a[href^="#"]').on('click',function (e) { e.preventDefault(); var target = this.hash; var $target = $(target); $('html, body').animate({ 'scrollTop': $target.offset().top }, 1000, 'swing', function() { $('.div').css('border', '1px solid red'); // изменение бордера дива с классом div }); }); }); 
  • Thank you for your help, I decided instead to put the frame .animate opacity - John Dick