Created
February 21, 2018 13:03
-
-
Save marios88/2fd500e8ea49b2f5f7ce54b16b9438df to your computer and use it in GitHub Desktop.
Boostrap v4 tab history
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
//refresh && link | |
var hash = window.location.hash; | |
hash && $('.nav a[href="' + hash + '"]').tab('show'); | |
//back - forward | |
window.onpopstate = function(event) { | |
if(window.location.hash == ''){ | |
//no hash in url show the tab you like! | |
$('.nav a[href="#nav-home"]').tab('show'); | |
}else{ | |
$('.nav a[href="' + window.location.hash + '"]').tab('show'); | |
} | |
} | |
$('.nav-tabs a').click(function (e) { | |
$(this).tab('show'); | |
var scrollmem = $('body').scrollTop() || $('html').scrollTop(); | |
window.location.hash = this.hash; | |
$('html,body').scrollTop(scrollmem); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment