-
-
Notifications
You must be signed in to change notification settings - Fork 78.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow anchor links to automatically load JS tabs #25220
Comments
You can always make a PR. |
You can obtain the url anchor directly with const anchor = window.location.hash;
$(`a[href="${anchor}"]`).tab('show') |
@alainravet if possible also offset it to the anchor section? |
never mind the offsetting function, this works for me.
|
@alainravet for this one |
Here is a code that handles a) changing the url on tab click and b) switching to it:
Indeed it would be great if it was a default and/or switchable feature (via Sass variables). |
Upfront warning - I have no real idea regarding scripts... |
Just for info, and for any others searching the same issue, this is the code that eventually worked for me, opening the tab, jumping to its location, and allowing an offset for the menu bar. $(document).ready(() => {
var url = window.location.href;
if (url.indexOf("#") > 0){
var activeTab = url.substring(url.indexOf("#") + 1);
$('.nav[role="tablist"] a[href="#'+activeTab+'"]').tab('show');
var position = $("#tab-options").offset().top -57;
$("html, body").animate({
scrollTop: position
}, 1000);
}
}); |
Currently it's necessary to add a small junk of JS (created below) to activate NAV tabs/pills based on the anchor link provided on the tab/pill itself when a page is loaded. This is for deep linking to a tab/pill on a page. This feature request is to integrate this behaviour automatically as part of bootstrap v4 JS.
The text was updated successfully, but these errors were encountered: