Reputation: 5770
Using bootstrap, I have set an example up here: http://fixitup.com.au/clients/bootstrap/issue.html
Using scrollto for the main site, and also twitter bootstraps, tabs. I find that when you click on a tab the page jumps up.
I added onclick="return false;"
to the href of the tabs.
Like:
<ul id="myTab" class="nav nav-tabs">
<li class="active"><a href="#about" data-toggle="tab" onclick="return false;">About Me</a></li>
<li><a href="#ripoffs" data-toggle="tab" onclick="return false;">My Ripoffs</a></li>
</ul>
I need scrollto and I need tabs... but I need to stop the page jumping, its driving me bonkers. Any suggestions ?
Added: the js for the scroll is in aruo.js code below:
// Any links with hash tags in them (can't do ^= because of fully qualified URL potential)
$('a[href*=#]').each(function() {
// Ensure it's a same-page link
var thisPath = filterPath(this.pathname) || locationPath;
if ( locationPath == thisPath
&& (location.hostname == this.hostname || !this.hostname)
&& this.hash.replace(/#/,'') ) {
// Ensure target exists
var $target = $(this.hash), target = this.hash;
if ($(target).length > 0) {
// Find location of target
var targetOffset = $target.offset().top;
$(this).click(function(event) {
// Prevent jump-down
event.preventDefault();
// Animate to target
$(scrollElem).animate({scrollTop: targetOffset}, 1100, 'swing', function() {
// Set hash in URL after animation successful
location.hash = target;
});
});
}
}
});
// Use the first element that is "scrollable" (cross-browser fix?)
function scrollableElement(els) {
for (var i = 0, argLength = arguments.length; i <argLength; i++) {
var el = arguments[i],
$scrollElement = $(el);
if ($scrollElement.scrollTop()> 0) {
return el;
} else {
$scrollElement.scrollTop(1);
var isScrollable = $scrollElement.scrollTop()> 0;
$scrollElement.scrollTop(0);
if (isScrollable) {
return el;
}
}
}
return [];
}
});
Upvotes: 1
Views: 4298
Reputation: 390
Can't you just modify your selector so the scroll functions aren't applied to the tabs?
Depending on what attr, classes etc.. are available.
In this example I use the :not selector to exclude elements with the class "foo"
For your example, changing the selector to something like:
$('a[href*=#]:not([data-toggle="tab"])').each(function() {
Might work?
Upvotes: 2