David Bridle writes: How did you get the tabbed menu to work in the headscape website?
I am not going to get into too much code as I am not the right person to teach that. I also think it is more important to show you the techniques rather than post code that can be copy and paste into your own site. If you want to learn how to actually reproduce what I have done then I recommend the excellent documentation on the jQuery site or the designers guide to jQuery.
Eventually I concluded that I wanted to use AJAX. Using Jeremy Keith’s HIJAX approach I built one page for each of the case studies found under the tabs. I then linked to these from the homepage tabs using normal hrefs. Clicking on each tab would load the appropriate page.
Each of these individual pages were complete with a header and footer as well as the content I wanted to include on the homepage.
This was achieved with a function that was triggered on clicking each tab. The function was attached unobtrusively (rather than included in the HTML itself) so I could easily remove it later if I wanted to alter the way the site worked.
The function carried out the following actions:
- It captured the url of each link
- Append to the links the specific element I wanted to import using AJAX
var addr = $("#csMenu a").href + " #caseStudies
- Load that content into the appropriate place on the page (which had the id = csCont)
- Applied some of the inbuilt effects in jQuery to make the animation fade in and out.
- Prevented the default action
In reality it was slightly more complex because I needed to trigger additional functions to add a popup facility to some of the links within the imported content. However, fundamentally that was it.
The problem with AJAX
A lot of people cleverer than me have been struggling with this issue and failed to come up with a solution. That is why some developers such as Brothercake recommend against the use of AJAX.
So there you have it. That is how I produced the tabs on the Headscape website. I would be fascinated to hear what other approaches people would have used. How could I have done it better?