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
45 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 51

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 51

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 51

Expert Comment

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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now