Solved

How do I get links not located within the tabs div to go to and open specific tabs?

Posted on 2016-09-14
5
65 Views
Last Modified: 2016-09-22
http://embroideredpatches.net/test/scouting/scout_custom_patches.html

I want the blue buttons to jump down to the tabs on the bottom of the page and also land on the matching tab. So, for example, if the blue "Woven Patch Pricelist" button is clicked, I want it to scroll down to the tabs and also open the "woven patches" tab. Right now if seems to be scrolling down but not activating the matching tab.

Does that makes sense?
0
Comment
Question by:underrugswept
  • 3
  • 2
5 Comments
 
LVL 55

Assisted Solution

by:Julian Hansen
Julian Hansen earned 500 total points
ID: 41798483
I believe this should do it
$('.btn-add-cart').click(function() {
  var target = 'a[href="' + $(this).attr('href') + '"]';
  $(target).tab('show');
});

Open in new window

0
 
LVL 1

Author Comment

by:underrugswept
ID: 41806571
That did work. Thanks. Sorry it took so long to respond; I got working on other things. Do you find that it lands about 100 pixels too low? Is that because of the navigation bar that stays on top of the page no matter what?
0
 
LVL 55

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41806740
The code above does not deal with the scrolling - that is happening because the target id is under the tab headings - the scroll be to place the id at the top of the screen - even if you take the menu away it will still scroll the tabs out of view.

To fix that you need your target points to be above the tabs.

What you could do is this
Change the
<div class="product-tab">

Open in new window

to
<div class="product-tab" id="product-tab">

Open in new window

Then your links change from
<a class="btn-add-cart" href="#100">100% Emb. Pricelist</a>

Open in new window

To
<a class="btn-add-cart" href="#product-tab" data-tab="#100">100% Emb. Pricelist</a>

Open in new window

Note all links now point to #product-tab and we have added a custom data attribute that now has the Tab target.
We change the jQuery to
$('.btn-add-cart').click(function() {
  var target = 'a[href="' + $(this).data('tab') + '"]';
  $(target).tab('show');
});

Open in new window

This gets us most of the way. What we are doing is pointing the links to the top of the Tab Menu rather than the individual tabs. This still puts the tabs under the menu.
We can get around that by changing the margin-top on the product-tab to padding and increasing it a bit
Line 4095 of styles.css
.product-tab {
  padding-top: 50px;
}

Open in new window

That should do it.
0
 
LVL 1

Author Comment

by:underrugswept
ID: 41810991
Perfect as always!
0
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 41811171
Thanks and you are welcome.
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question