Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
97 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 60

Assisted Solution

by:Julian Hansen
Julian Hansen earned 2000 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 60

Accepted Solution

by:
Julian Hansen earned 2000 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 60

Expert Comment

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

971 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