I'm rusty at javascript and HTML, and trying to get back into it.
Here's the sample code of the element I'd like to modify:
<div id="tabContainer" class="table">
<h1>Container</h1>
<ul class="tabs">
<li>Tab 1</li>
<li>Tab 2</li>
<li>Tab 3</li>
</ul>
<div id="tab_display">
<div id="tab1" class="tab_content"></div>
<div id="tab2" class="tab_content"></div>
<div id="tab3" class="tab_content"></div>
</div>
</div>
I'm using a version of jQuery Accordion to switch between tabs,and it works without any trouble. Clicking on tab 2, while tab 1 is selected, will clear 'tab_display' and display the contents of tab 2.
I would like to control what tab is displayed, by clicking for a button for example.
If tab 1 is being displayed and I click another button on the page, I'd like for a specific tab to be displayed (show the selection on the 'tabs' list, and also show the contents in the 'tab_dsiplay').
How can I do this?
Thanks!
Try using the solution here open-jquery-accordion-panel-with-link-outside-of-acccordion
Demo here.
Related
First of all, what do I mean by "fluid page"? I mean one long page that is broken into id sections which show those id's as pages. It's most basic structure looks like this:
<div class="mainnav">
<ul>
<li>PAGE 1</li>
<li>PAGE 2</li>
<li>PAGE 3</li>
<li>PAGE 4</li>
<li>PAGE 5</li>
</ul>
</div>
<div id="page1" class="container-fluid"> Page 1 content </div>
<div id="page2" class="container-fluid"> Page 2 content </div>
<div id="page3" class="container-fluid"> Page 3 content </div>
<div id="page4" class="container-fluid"> Page 4 content </div>
<div id="page5" class="container-fluid"> Page 5 content </div>
<!-- sticky footer -->
<div class="footer"></div>
So as you can see whenever the you hit the menu item for that ID, the content slides up until it reaches that Id and it displays the content as if it was a different page. Easy enough!
My problem is, I have the footer sticky and I did that so that when you click to the next page (ID) the footer is still there, EXCEPT, I don't want it to show when #page1 is selected.
I attempted to build a small JS, but my JS is less than great. Here is my attempt
<script type="text/javascript">
function hideFooter(){
$("#homeContainer").css(display:none);
}
$(document).ready(function() {
hideFooter();
});
</script>
Obviously, not working. Here is a FIDDLE that you can use.
Any ideas!?
You just need to add a handler on the .mainnav a tags and toggle as appropriate:
$(document).ready(function() {
Viewport();
$(window).bind('resize', Viewport);
$('.mainnav a').click(function(){
if (this.href.indexOf('#page1') == -1) {
$('.footer').show();
} else {
$('.footer').hide();
}
});
});
http://jsfiddle.net/taHCv/4/
I am using the Bootstrap framework through out the entire site for the responsive design ability. I am also using AJAX calls to switch between every page. On one page I am using the Bootstrap tabs to switch between page contents. Everything works perfectly when you are directed to the page through any of the ajax links but if you manually type in the url the tab contents wont change. The tabs themselves will change when you click on them but the content stays on the original content. I originally though it might have something to do with the javascript I'm using so that you can direct the user to a certain tab with a hashtag but it still doesn't work when I remove the code. Here is the code:
<div class="tabbable"> <!-- Only required for left/right tabs -->
<ul class="nav nav-tabs">
<li class="active">Tab 1</li>
<li>Tab 2</li>
<li>Tab 3</li>
<li>Tab 4</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab1">
Tab #1
</div>
<div class="tab-pane" id="tab2">
Tab #2
</div>
<div class="tab-pane" id="tab3">
Tab #3
</div>
<div class="tab-pane" id="tab4">
Tab #4
</div>
</div>
<script>
$(function(){
if (window.location.hash) {
var hash = window.location.hash;
var tab = $('[data-toggle="tab"][href="' + hash + '"]');
tab.show();
tab.tab('show');
}
});
</script>
Can anyone help me with this?
You have to add a listener to the hashchange window event.
You probably opened the page without a hash. At this point, your script was executed. When you change the hash in your adress bar, the page will not be reloaded. So there is no-one to handle that event. For this you have the hashchange event to react to such changes.
See the MDN documentation for more info and examples on this event.
If you are using jQuery, check out this answer.
I'm new to Foundation 4 and am currently trying to do the following:
I'm using the section-container horizontal-nav and was wondering if anyone knows the configuration to get the section container to display its content first by default instead of hiding it until it's been clicked? So when the page loads, the section will be shown first until the user clicks on "Section 1".
<div class="section-container horizontal-nav" data-section="horizontal-nav">
<section>
<p class="title" data-section-title>
Section 1
</p>
<div class="content" data-section-content>
<ul class="side-nav">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
<li class="divider"></li>
<li>Link 1</li>
</ul>
</div>
Tried adding active into the class attribute?
<div class="content active" data-section-content>
The section is placed as a horizontal nav-bar and I'd like for it to
be shown when the page loads as if the user has already clicked on it.
You can achieve this by giving you menu items an id and open that menu in jquery.
Section 1
then add this to the script section of your page:
$(function () {
$("#menu1").click();
});
Hi I am trying to create a one page website that contains multiple div's about the same size as the window.The website will have a menu that will refer to each div on the page.What I want to do is animate the window when the user clicks on one of the menu links to it's coresponding div.
http://www.nistoralexandru.comule.com/div.jpg
When a user clicks on a link I need the window to animate to that div similar to this site:
http://shahkaarshah.com/
How can I do this?
The site you're linking to is built with Flash, replicating the animation of different page elements with javascript should'nt be to hard, but there's really no quick "one size fits all" function to do it.
Here's a quick example of how it's usually done :
Build some sort of HTML structure:
<div id="site">
<div id="main" class="page">
<ul>
<li>Page 1</li>
<li>Page 2</li>
<li>Page 3</li>
<li>Page 4</li>
<li>Page 5</li>
</ul>
</div>
<div id="page1" class="page">Back</div>
<div id="page2" class="page">Back</div>
<div id="page3" class="page">Back</div>
<div id="page4" class="page">Back</div>
<div id="page5" class="page">Back</div>
</div>
And animate it around the viewport with a little javascript:
$('.page a').on('click', function(e) {
e.preventDefault();
var href = $(this).attr('href'),
top = $(href).css('top'),
left = $(href).css('left');
$("#site").animate({top: '-'+top, left: '-'+left}, 1000);
});
Here's a FIDDLE
You might be meaning something like accordion?
http://jqueryui.com/demos/accordion/
There are many easy-to-use accordion plugins for jquery, so they might be easier to use for complex animations than coding from scratch.
Based on your added information, maybe a grid accordion such as this?
http://css-tricks.com/examples/InfoGrid/
I have an application which uses phonegap and jquery mobile and it has tabs like this
<div data-role="header">
<div data-role="tabs">
<ul>
<li>Tab 1</li>
<li>Tab 2</li>
<li>Tab 3</li>
</ul>
</div>
</div>
<div data-role="content">
<div id="tab-1">
<h2>Here is the second tab</h2>
</div>
<div id="tab-2">
<h2>Here is the second tab</h2>
</div>
<div id="tab-3">
<h2>Here is the third tab</h2>
</div>
</div>
Now i need to do the following things
How to add a div dynamically to any of the tab?
How to show progress bar for about 10 seconds and then display the result.
You can dynamically add DOM elements with jQuery like this:
$('#container').append("<div></div>");
For jQuery-Mobile, you'd have to call refresh on any library specific constructs, such as listviews.