Try this
$(document).ready(function(){ $('.tab').on('click', function() { var $me = $(this); var id = $me.data("id"); var $tab = $('.tab[data-id=' + id + ']'); var $tabBody = $('.content[data-id = ' + id + '-content]'); $('.tab.tab-sel').removeClass('tab-sel'); $tab.addClass('tab-sel'); $('.content').fadeOut(500); $tabBody.fadeIn(500); //ΠΡΠ»ΠΈ ΠΊΠ»ΠΈΠΊ ΠΏΠΎ Π½ΠΈΠΆΠ½Π΅ΠΉ Π²ΠΊΠ»Π°Π΄ΠΊΠ΅(ΠΠ°ΠΏΡΠΈΠΌΠ΅Ρ ΠΊΠ»Π°ΡΡ .bottom) if($me.is('.bottom')) { var offset = $tabBody.offset().top; $("body,html").animate({scrollTop: offset}, 500); } }); });
Without animation, if ugly it turns out
$(document).ready(function(){ $('.tab').on('click', function() { var $me = $(this); var id = $me.data("id"); var $tab = $('.tab[data-id=' + id + ']'); var $tabBody = $('.content[data-id = ' + id + '-content]'); $('.tab.tab-sel').removeClass('tab-sel'); $tab.addClass('tab-sel'); $('.content').hide(); $tabBody.show(); //ΠΡΠ»ΠΈ ΠΊΠ»ΠΈΠΊ ΠΏΠΎ Π½ΠΈΠΆΠ½Π΅ΠΉ Π²ΠΊΠ»Π°Π΄ΠΊΠ΅(ΠΠ°ΠΏΡΠΈΠΌΠ΅Ρ ΠΊΠ»Π°ΡΡ .bottom) if($me.is('.bottom')) { var offset = $tabBody.offset().top; $("body,html").scrollTop(offset); } }); });
var offset = $('<ΠΠ»Π΅ΠΌΠ΅Π½Ρ>').offset().top;
- find out the indent from the top of the screen.$("body,html").animate({scrollTop: offset}, 500);
- smoothly scroll to this place. 500 is the time in milliseconds for the animation - user200141.bottom
. The code does not change much, now I will write. - user200141