I'm using a bootstrap tabs to create a timeline like tabs. It works only first 4 times and then stops changing after that.
I made a fiddle please look into it.
code:
<ul class="nav nav-tabs" role="tablist" id="timeline">
<div class="col-sm-3"><li role="presentation">2011</li></div>
<div class="col-sm-3"><li role="presentation">2013</li></div>
<div class="col-sm-3"><li role="presentation">2014</li></div>
<div class="col-sm-3"><li role="presentation">2016</li></div>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane fade in active" id="2011">
<p>1</p>
</div>
<div role="tabpanel" class="tab-pane fade" id="2013">
<p>2</p>
</div>
<div role="tabpanel" class="tab-pane fade" id="2014">
<p>
3</p>
</div>
<div role="tabpanel" class="tab-pane fade" id="2016">
<p>
4
</p>
</div>
</div>
script:
$('#timeline a').click(function (e) {
e.preventDefault()
$(this).tab('show')
})
Make sure you close off your code statements with a semi colon ;
Also needed to remove the active class for the tabs li.
Web dev tools are your friend. watch for classes which may be added
$('#timeline a').click(function (e) {
$('#timeline li').removeClass('active');
e.preventDefault();
$(this).tab('show');
});
here is fiddle https://jsfiddle.net/5253gmpu/
Related
here is my accordion code:
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Collapsible Group Item #1
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body" id="myPanelContent">
Accordion Panel 1 Content
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Collapsible Group Item #2
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
Accordion Panel 2 Content
</div>
</div>
</div>
</div>
I want a link from another page to open the No 1 panel (#myPanelContent) and show the content.
Link example:
Go to Panel 1 content
The true is that i used some solutions from stackoverflow but not worked. A detailed explain how to use the code will be much appreciated as I am novice in javascript.
Thanks in advance.
I'll add an answer in reply to my comment.
you need to check if there is a hash present in the URL, if so then show the accordion panel, you can accomplish this likes so:
$(function(){
// check if there is a hash in the url
if ( window.location.hash != '' )
{
// remove any accordion panels that are showing (they have a class of 'in')
$('.collapse').removeClass('in');
// show the panel based on the hash now:
$(window.location.hash + '.collapse').collapse('show');
}
});
This code uses jQuery of course, but i'd imagine you are using that already if you are using bootstrap's accordion?
give the link like above mentioned
and add the below script in the page where you want to show the active div
<script type="text/javascript">
var url = window.location.toString();
if (url.match('#')) {
$('.nav-tabs a[href="#'+url.split('#')[1]+'"]').tab('show');
}
</script>
um developing a website and that should has few tabs according to my dream,
but thing is when I click a tab it shows only contents which is between heading tag,not P tags,
Here's my code.please help me to fulfill my dream :-D
<div class="panel panel-default">
<div class="panel-body tabs">
<ul class="nav nav-pills" data-tabs="tabs">
<li class="active">Tab1
</li>
<li>Tab2
</li>
<li>Tab3
</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade in active" id="tab1">
<h4>Heading1</h4>
<p>text</p>
</div>
<div class="tab-pane fade" id="tab2">
<h4>Heading2</h4>
<p>text</p>
</div>
<div class="tab-pane fade" id="tab3">
<h4>Heading3</h4>
<p>text</p>
</div>
</div>
</div>
</div>
I think you were missing the jQuery link.
The code works.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<div class="panel panel-default">
<div class="panel-body tabs">
<ul class="nav nav-pills" data-tabs="tabs">
<li class="active">Tab1
</li>
<li>Tab2
</li>
<li>Tab3
</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade in active" id="tab1">
<h4>Heading1</h4>
<p>text in p</p>
</div>
<div class="tab-pane fade" id="tab2">
<h4>Heading2</h4>
<p>text in p</p>
</div>
<div class="tab-pane fade" id="tab3">
<h4>Heading3</h4>
<p>text in p</p>
</div>
</div>
</div>
</div>
Output :
You need to Enable tabbable tabs via JavaScript
<script>
$('.nav-pills a').click(function (e) {
e.preventDefault()
$(this).tab('show')
})
</script>
I tried to setup bootstrap tabs without javascript (like written here: http://getbootstrap.com/javascript/#markup).
Code copied from bootstrap page:
<div>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">Home</li>
<li role="presentation">Profile</li>
<li role="presentation">Messages</li>
<li role="presentation">Settings</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="home">Tab 1</div>
<div role="tabpanel" class="tab-pane" id="profile">Tab 2</div>
<div role="tabpanel" class="tab-pane" id="messages">Tab 3</div>
<div role="tabpanel" class="tab-pane" id="settings">Tab 4</div>
</div>
</div>
https://jsfiddle.net/Zoker/w6xeyznk/
As you can see, it does not work and I don't know why. Anybody got an idea?
Have you included the jquery.js and the bootstrap.js it's important for work because you don't have to code the js part but bootstap already have it.
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
Hi
i have try to loop throw data in "Categories" Table and it works - i got data when i open View in first time but if i click on a tab to see its content i got only first record ?
i don't know why i lose all data i got in first time ?
Razor Code:
#section personAds{
<h2 class="title text-center">Person Ads</h2>
<div class="col-sm-12">
<ul class="nav nav-tabs">
<li class="active">Home</li>
<li>Cars</li>
</ul>
</div>
<div class="tab-content">
#foreach (var personItems in Model.Where(isCompany => isCompany.isCompany == false))
{
<div class="tab-pane fade active in" id="propertytab">
<div class="col-sm-3">
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfoslide text-center">
<img src="#Url.Content(personItems.catImage)" alt="" />
<h4>#personItems.catName</h4>
<i class="#personItems.classIcon"></i>More
</div>
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="carstab">
<div class="col-sm-3">
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfoslide text-center">
<img src="#Url.Content(personItems.catImage)" alt="" />
<h4>#personItems.catName</h4>
<i class="#personItems.classIcon"></i>More
</div>
</div>
</div>
</div>
</div>
}
</div>
}
Controller Code:
public ActionResult Contact()
{
var model = _db.Categories.ToList();
return View(model);
}
and i try to remove where condition and i got same result - when i click on any tab i got only first record ?!
Please see the Video of Problem ... Click Here
From the look of your code I think you have simply got your 'foreach' in the wrong position.
It looks like you are creating repeated 'tab' DIV's which will each have just one record in.
This is probably somewhat better, notice I have moved the 'propertytab' outside of the #foreach
<div class="tab-pane fade active in" id="propertytab">
#foreach (var personItems in Model.Where(isCompany => isCompany.isCompany == false))
{
<div class="col-sm-3">
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfoslide text-center">
<img src="#Url.Content(personItems.catImage)" alt="" />
<h4>#personItems.catName</h4>
<i class="#personItems.classIcon"></i>More
</div>
</div>
</div>
</div>
}
</div>
<div class="tab-pane fade" id="carstab">
#foreach (var personItems in Model.Where(isCompany => isCompany.isCompany == false))
<div class="col-sm-3">
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfoslide text-center">
<img src="#Url.Content(personItems.catImage)" alt="" />
<h4>#personItems.catName</h4>
<i class="#personItems.classIcon"></i>More
</div>
</div>
</div>
</div>
}
</div>
This should show exactly what I am struggling with:
http://jsfiddle.net/PaulHighten/c5knqdgd/
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingParis">
<h4 class="panel-title">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseParis" aria-expanded="true" aria-controls="collapseParis">
Eiffel Tower, Paris
</a>
</h4>
</div>
<div id="collapseParis" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingParis">
<div class="panel-body">
<div class="googlemap">
<iframe width="600" height="450" frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/place?q=Eiffel%20Tower%2C%20Avenue%20Anatole%20France%2C%20Paris%2C%20France&key=AIzaSyAFUKSu28KvFk67YcSlUWeUJ2TpcifSVmQ"></iframe>
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingLondon">
<h4 class="panel-title">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseLondon" aria-expanded="false" aria-controls="collapseLondon">
Trafalgar Square, London
</a>
</h4>
</div>
<div id="collapseLondon" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingLondon">
<div class="panel-body">
<div class="googlemap">
<iframe width="600" height="450" frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/place?q=Trafalgar%20Square%2C%20London%2C%20United%20Kingdom&key=AIzaSyAFUKSu28KvFk67YcSlUWeUJ2TpcifSVmQ"></iframe>
</div>
</div>
</div>
</div>
The Paris panel shows the map correctly as it has a class of "in".
The London panel does not have that class which means bootstrap applies display: none; to that panel. I'm assuming that stops the iframe from running it's http request properly.
Can the Google Maps Embed API be used to achieve this? I've seen lots of questions relating to API v3 and initialize() calls, but struggled to find anything that related to making the embed iframe code work.
Thanks in advance.
=================
Edit: Code I used which solved the problem (slight modification of Christina's answer to only update the relevant iframe once):
$('[data-toggle="collapse"]').click('show.bs.collapse', function() {
var mapFrame = $($(this).attr('href') + ' .googlemap iframe');
if (!$(mapFrame).hasClass('map-refreshed')) {
mapFrame.attr('src', mapFrame.attr('src')+'');
mapFrame.addClass('map-refreshed');
}
});
Refresh the iframe source on the shown.bs.collapse OR show.bs.collapse function
$('[data-toggle="collapse"]').click('shown.bs.collapse', function() {
var googleIframe = $('.googlemap iframe');
googleIframe.attr('src',googleIframe.attr('src')+'');
});
DEMO: http://jsfiddle.net/ekba9y8w/
Assumes that the .googlemap is parent of the iframe.
Paul Highten's update so it doesn't keep on refreshing:
$('[data-toggle="collapse"]').click('show.bs.collapse', function() {
var mapFrame = $($(this).attr('href') + ' .googlemap iframe');
if (!$(mapFrame).hasClass('map-refreshed')) {
mapFrame.attr('src', mapFrame.attr('src')+'');
mapFrame.addClass('map-refreshed');
}
});