Jquery Scrolling Tabs
- ScottG
- Proficient


- Joined: Jul 06, 2010
- Posts: 263
- Status: Online
Before I dive into the coding I was wondering it anyone has came across a Jquery scrolling tabs example much like the Ex Js 4 advanced tabs http://try.sencha.com/extjs/4.0.7/examp ... /tabs-adv/
I have found some Jquery based examples but the seem buggy at least in Firefox 18. http://www.seyfertdesign.com/jquery/demo.html but they also don't have the scrolling that I'm looking for. So if anyone has seen anything let me know. I will most likely start making my own in a couple days. When I do I will post the script here.
I have found some Jquery based examples but the seem buggy at least in Firefox 18. http://www.seyfertdesign.com/jquery/demo.html but they also don't have the scrolling that I'm looking for. So if anyone has seen anything let me know. I will most likely start making my own in a couple days. When I do I will post the script here.
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
January 15th, 2013, 11:06 am
- Zealous
- Guru


- Joined: Apr 15, 2011
- Posts: 1195
- Loc: Sydney
- Status: Online
- ScottG
- Proficient


- Joined: Jul 06, 2010
- Posts: 263
- Status: Online
That's true but the issue is that the tabs use float left and when the hit the end it wraps the tabs to the next line. This is the basic functionality of the Jquery ui tabs function. I'd have to solve that issue before anything else.
So I started working on it today and this is what I came up with on my first pass
It's a bit messy and not commented well at all and I'm still going to add features to it.
If any one has a good extension script for a jquery ui widget I'd love to see it I spent most my time trying to extend the create function in the tabs and add to the options I kept getting close but then there would always be some strange error that happened so I decided on this
I would like to be able to do this. (I'm close to getting to this point)
Well I'll work on this tomorrow I was suppose to be off of work about 15 minutes ago. If any ideas please let me know.
So I started working on it today and this is what I came up with on my first pass
It's a bit messy and not commented well at all and I'm still going to add features to it.
If any one has a good extension script for a jquery ui widget I'd love to see it I spent most my time trying to extend the create function in the tabs and add to the options I kept getting close but then there would always be some strange error that happened so I decided on this
JAVASCRIPT Code: [ Select ]
var tabs = $("#tabs").scrollableTabs();
- var tabs = $("#tabs").scrollableTabs();
I would like to be able to do this. (I'm close to getting to this point)
JAVASCRIPT Code: [ Select ]
var tabs = $("#tabs").tabs({scrollable:true, scrollSpeed: 40, scollToActive:true});
- var tabs = $("#tabs").tabs({scrollable:true, scrollSpeed: 40, scollToActive:true});
Well I'll work on this tomorrow I was suppose to be off of work about 15 minutes ago. If any ideas please let me know.
Attachments:
- ScottG
- Proficient


- Joined: Jul 06, 2010
- Posts: 263
- Status: Online
Ok so some time away from coding did me good I've rewritten the script to work the way I want it to. This is the core of the script I am still adding to it.
Though it is not complete I'm posting the code so it could be tested by others to see if there are any issues I've missed so far
// Basic jQuery UI tabs
var tabs = $("#tabs").tabs();
// Basic jQuery UI tabs with scrollable capability
var tabs = $("#tabs").tabs({scrollable:true});
// Added features
var tabs = $("#tabs").tabs({scrollable:true, scrollSpeed: 100, easing: 'easeOutBounce', duration: 500});
// Features to be added
var tabs = $("#tabs").tabs({scrollToActive});
I know that scroll speed and the duration may seem like one in the same. Perhaps I could have used a different term.
scrollSpeed - Is the amount the tabs move in a single click or if the button is held down the amount the tabs move every time the function to move them is called
duration - Is the amount of time for the animation to take place.
If there is a better term please let me know also let me know if anyone has found any issues.
Though it is not complete I'm posting the code so it could be tested by others to see if there are any issues I've missed so far
JAVASCRIPT Code: [ Select ]
// Basic jQuery UI tabs
var tabs = $("#tabs").tabs();
// Basic jQuery UI tabs with scrollable capability
var tabs = $("#tabs").tabs({scrollable:true});
// Added features
var tabs = $("#tabs").tabs({scrollable:true, scrollSpeed: 100, easing: 'easeOutBounce', duration: 500});
// Features to be added
var tabs = $("#tabs").tabs({scrollToActive});
- // Basic jQuery UI tabs
- var tabs = $("#tabs").tabs();
- // Basic jQuery UI tabs with scrollable capability
- var tabs = $("#tabs").tabs({scrollable:true});
- // Added features
- var tabs = $("#tabs").tabs({scrollable:true, scrollSpeed: 100, easing: 'easeOutBounce', duration: 500});
- // Features to be added
- var tabs = $("#tabs").tabs({scrollToActive});
I know that scroll speed and the duration may seem like one in the same. Perhaps I could have used a different term.
scrollSpeed - Is the amount the tabs move in a single click or if the button is held down the amount the tabs move every time the function to move them is called
duration - Is the amount of time for the animation to take place.
If there is a better term please let me know also let me know if anyone has found any issues.
Attachments:
- ScottG
- Proficient


- Joined: Jul 06, 2010
- Posts: 263
- Status: Online
Ok even though I'm not at work I can't stop working on this. It's too much fun
So I did find a few things that caused some issues and fixed them. Also it looks like i might have uploaded the wrong zip file last time ... Oh well it has been updated since then.
OK so this is where I stand. All the features i want on it at this point are on the updated script it has been better commented and a a lot has been added.
usage
There is some strangeness that happens when you pull the tab off the bar and drop it. It activates and scroll that the the far left. Ill work on that later
OK so this is where I stand. All the features i want on it at this point are on the updated script it has been better commented and a a lot has been added.
usage
JAVASCRIPT Code: [ Select ]
// Basic jQuery UI tabs
var tabs = $("#tabs").tabs();
// Basic jQuery UI tabs with scrollable capability
var tabs = $("#tabs").tabs({scrollable:true});
// Added features
var tabs = $("#tabs").tabs({scrollable:true, scrollSpeed: 100, easing: 'easeOutBounce', duration: 500, scrollToActive:true, leftButton: '<button id="left_button" href="#"><span></span></button>', rightButton: '<button id="right_button" href="#"><span></span></button>'});
var tabs = $("#tabs").tabs();
// Basic jQuery UI tabs with scrollable capability
var tabs = $("#tabs").tabs({scrollable:true});
// Added features
var tabs = $("#tabs").tabs({scrollable:true, scrollSpeed: 100, easing: 'easeOutBounce', duration: 500, scrollToActive:true, leftButton: '<button id="left_button" href="#"><span></span></button>', rightButton: '<button id="right_button" href="#"><span></span></button>'});
- // Basic jQuery UI tabs
- var tabs = $("#tabs").tabs();
- // Basic jQuery UI tabs with scrollable capability
- var tabs = $("#tabs").tabs({scrollable:true});
- // Added features
- var tabs = $("#tabs").tabs({scrollable:true, scrollSpeed: 100, easing: 'easeOutBounce', duration: 500, scrollToActive:true, leftButton: '<button id="left_button" href="#"><span></span></button>', rightButton: '<button id="right_button" href="#"><span></span></button>'});
There is some strangeness that happens when you pull the tab off the bar and drop it. It activates and scroll that the the far left. Ill work on that later
Attachments:
- ScottG
- Proficient


- Joined: Jul 06, 2010
- Posts: 263
- Status: Online
So for anyone still following along with this I fix the strange behavior that was being caused by pulling the tab off the bar.
When you are setting up sort-ability on this script you need to define tabs.tabs("option", "sorting", true); in the stop function. This will tell the script that we are sorting and not just selecting a tab. I did it this way so I didn't need to combine the sortable widget into the tabs widget.
I've also made a new function with the only purpose to disable/enable the arrow buttons with this function came the function that if we had enough tabs to scroll and removed the tabs both the arrows will disable if we then add tabs or re-size the window to where we have enough tabs to scroll they will enable.
Also with this I discovered that my extension to the scollParent function was causing too much recursion errors and I fixed that as well.
One thing that I'm not satisfied on is some of the equations I use seem Hacky there has got to be a better formula for this the two equations in question are.
If anyone can help get these seem not so hacked that would be great. See the below functions for usage
When you are setting up sort-ability on this script you need to define tabs.tabs("option", "sorting", true); in the stop function. This will tell the script that we are sorting and not just selecting a tab. I did it this way so I didn't need to combine the sortable widget into the tabs widget.
JAVASCRIPT Code: [ Select ]
tabs.find(".ui-tabs-nav").sortable({
//axis: "x",
stop: function() {
tabs.tabs("refresh");
tabs.tabs("option", "sorting", true);
},
containment: $("#bar_container")
});
//axis: "x",
stop: function() {
tabs.tabs("refresh");
tabs.tabs("option", "sorting", true);
},
containment: $("#bar_container")
});
- tabs.find(".ui-tabs-nav").sortable({
- //axis: "x",
- stop: function() {
- tabs.tabs("refresh");
- tabs.tabs("option", "sorting", true);
- },
- containment: $("#bar_container")
- });
I've also made a new function with the only purpose to disable/enable the arrow buttons with this function came the function that if we had enough tabs to scroll and removed the tabs both the arrows will disable if we then add tabs or re-size the window to where we have enough tabs to scroll they will enable.
Also with this I discovered that my extension to the scollParent function was causing too much recursion errors and I fixed that as well.
One thing that I'm not satisfied on is some of the equations I use seem Hacky there has got to be a better formula for this the two equations in question are.
JAVASCRIPT Code: [ Select ]
(element.width() - 1 + element.scrollLeft()) < element[0].scrollWidth
(settings.bar_width < $('#tabs_container').width() - 5) ? $('#tabs_container').width() - 5
(settings.bar_width < $('#tabs_container').width() - 5) ? $('#tabs_container').width() - 5
- (element.width() - 1 + element.scrollLeft()) < element[0].scrollWidth
- (settings.bar_width < $('#tabs_container').width() - 5) ? $('#tabs_container').width() - 5
If anyone can help get these seem not so hacked that would be great. See the below functions for usage
JAVASCRIPT Code: [ Select ]
// This function will be used to scroll the the tabs.
move_bar: function(element, left, that) {
// Check to see if we are going to scroll left
if(left) {
// Check to see if the scroll left is greater than 0
if(element.scrollLeft() > 0) {
// Start the scrolling
element.animate({ scrollLeft : "-=" + that.options.scrollSpeed }, {queue: true, easing: that.options.easing, duration: that.options.duration, complete: function(){
// Check to see if we are currenly scrolling
if(settings.scrolling) {
// We are still scrolling so call the function again
that.move_bar(element, left, that);
}
// Disable the buttons
that._disable_buttons(element);
}});
} else {
// Disable the buttons
that._disable_buttons(element);
}
} else {
// Check to see if the Scroll if at the max
if((element.width() - 1 + element.scrollLeft()) < element[0].scrollWidth) {
// Start the scrolling
element.animate({ scrollLeft : "+=" + that.options.scrollSpeed }, {queue: true, easing: that.options.easing, duration: that.options.duration, complete: function(){
// Check to see if we are currenly scrolling
if(settings.scrolling) {
// We are still scrolling so call the function again
that.move_bar(element, left, that);
}
// Disable the buttons
that._disable_buttons(element);
}});
} else {
// Disable the buttons
that._disable_buttons(element);
}
}
},
// This function will diable the arrows buttons if needed
_disable_buttons: function(element) {
// Remove the disabled states
$("#left_button").removeAttr("disabled").removeClass("ui-state-disabled");
$("#right_button").removeAttr("disabled").removeClass("ui-state-disabled");
// Check to see if we are at the begining of the scrolling element
if(element.scrollLeft() == 0) {
// Set to the max scroll
element.scrollLeft(0);
// Disable the left button
$("#left_button").attr("disabled", "disabled").addClass("ui-state-disabled");
}
// Check to see if we are at the end of the scrolling element
if((element.width() - 1 + element.scrollLeft()) >= element[0].scrollWidth) {
// Set to the max scroll
element.scrollLeft(element[0].scrollWidth);
// Disable the right button
$("#right_button").attr("disabled", "disabled").addClass("ui-state-disabled");
}
// Check to see if there is even an ability to scroll
if(element.width() == element[0].scrollWidth) {
// Disable the left and right button
$("#left_button").attr("disabled", "disabled").addClass("ui-state-disabled");
$("#right_button").attr("disabled", "disabled").addClass("ui-state-disabled");
}
},
// This function will set the ULs width
_get_bar_width: function() {
// Rest the bar width
settings.bar_width = 0;
// Loop through the UL LI tags
this.element.find(".ui-tabs-nav:first li").each(function() {
// Add the outWidth of the LI to the bar_width varible
settings.bar_width += $(this).outerWidth(true);
});
// This line fixes any wrapping issue that are caused by the first two tabs
settings.bar_width = (settings.bar_width < $('#tabs_container').width() - 5) ? $('#tabs_container').width() - 5 : settings.bar_width;
// Return the width
return settings.bar_width;
}
move_bar: function(element, left, that) {
// Check to see if we are going to scroll left
if(left) {
// Check to see if the scroll left is greater than 0
if(element.scrollLeft() > 0) {
// Start the scrolling
element.animate({ scrollLeft : "-=" + that.options.scrollSpeed }, {queue: true, easing: that.options.easing, duration: that.options.duration, complete: function(){
// Check to see if we are currenly scrolling
if(settings.scrolling) {
// We are still scrolling so call the function again
that.move_bar(element, left, that);
}
// Disable the buttons
that._disable_buttons(element);
}});
} else {
// Disable the buttons
that._disable_buttons(element);
}
} else {
// Check to see if the Scroll if at the max
if((element.width() - 1 + element.scrollLeft()) < element[0].scrollWidth) {
// Start the scrolling
element.animate({ scrollLeft : "+=" + that.options.scrollSpeed }, {queue: true, easing: that.options.easing, duration: that.options.duration, complete: function(){
// Check to see if we are currenly scrolling
if(settings.scrolling) {
// We are still scrolling so call the function again
that.move_bar(element, left, that);
}
// Disable the buttons
that._disable_buttons(element);
}});
} else {
// Disable the buttons
that._disable_buttons(element);
}
}
},
// This function will diable the arrows buttons if needed
_disable_buttons: function(element) {
// Remove the disabled states
$("#left_button").removeAttr("disabled").removeClass("ui-state-disabled");
$("#right_button").removeAttr("disabled").removeClass("ui-state-disabled");
// Check to see if we are at the begining of the scrolling element
if(element.scrollLeft() == 0) {
// Set to the max scroll
element.scrollLeft(0);
// Disable the left button
$("#left_button").attr("disabled", "disabled").addClass("ui-state-disabled");
}
// Check to see if we are at the end of the scrolling element
if((element.width() - 1 + element.scrollLeft()) >= element[0].scrollWidth) {
// Set to the max scroll
element.scrollLeft(element[0].scrollWidth);
// Disable the right button
$("#right_button").attr("disabled", "disabled").addClass("ui-state-disabled");
}
// Check to see if there is even an ability to scroll
if(element.width() == element[0].scrollWidth) {
// Disable the left and right button
$("#left_button").attr("disabled", "disabled").addClass("ui-state-disabled");
$("#right_button").attr("disabled", "disabled").addClass("ui-state-disabled");
}
},
// This function will set the ULs width
_get_bar_width: function() {
// Rest the bar width
settings.bar_width = 0;
// Loop through the UL LI tags
this.element.find(".ui-tabs-nav:first li").each(function() {
// Add the outWidth of the LI to the bar_width varible
settings.bar_width += $(this).outerWidth(true);
});
// This line fixes any wrapping issue that are caused by the first two tabs
settings.bar_width = (settings.bar_width < $('#tabs_container').width() - 5) ? $('#tabs_container').width() - 5 : settings.bar_width;
// Return the width
return settings.bar_width;
}
- // This function will be used to scroll the the tabs.
- move_bar: function(element, left, that) {
- // Check to see if we are going to scroll left
- if(left) {
- // Check to see if the scroll left is greater than 0
- if(element.scrollLeft() > 0) {
- // Start the scrolling
- element.animate({ scrollLeft : "-=" + that.options.scrollSpeed }, {queue: true, easing: that.options.easing, duration: that.options.duration, complete: function(){
- // Check to see if we are currenly scrolling
- if(settings.scrolling) {
- // We are still scrolling so call the function again
- that.move_bar(element, left, that);
- }
- // Disable the buttons
- that._disable_buttons(element);
- }});
- } else {
- // Disable the buttons
- that._disable_buttons(element);
- }
- } else {
- // Check to see if the Scroll if at the max
- if((element.width() - 1 + element.scrollLeft()) < element[0].scrollWidth) {
- // Start the scrolling
- element.animate({ scrollLeft : "+=" + that.options.scrollSpeed }, {queue: true, easing: that.options.easing, duration: that.options.duration, complete: function(){
- // Check to see if we are currenly scrolling
- if(settings.scrolling) {
- // We are still scrolling so call the function again
- that.move_bar(element, left, that);
- }
- // Disable the buttons
- that._disable_buttons(element);
- }});
- } else {
- // Disable the buttons
- that._disable_buttons(element);
- }
- }
- },
- // This function will diable the arrows buttons if needed
- _disable_buttons: function(element) {
- // Remove the disabled states
- $("#left_button").removeAttr("disabled").removeClass("ui-state-disabled");
- $("#right_button").removeAttr("disabled").removeClass("ui-state-disabled");
- // Check to see if we are at the begining of the scrolling element
- if(element.scrollLeft() == 0) {
- // Set to the max scroll
- element.scrollLeft(0);
- // Disable the left button
- $("#left_button").attr("disabled", "disabled").addClass("ui-state-disabled");
- }
- // Check to see if we are at the end of the scrolling element
- if((element.width() - 1 + element.scrollLeft()) >= element[0].scrollWidth) {
- // Set to the max scroll
- element.scrollLeft(element[0].scrollWidth);
- // Disable the right button
- $("#right_button").attr("disabled", "disabled").addClass("ui-state-disabled");
- }
- // Check to see if there is even an ability to scroll
- if(element.width() == element[0].scrollWidth) {
- // Disable the left and right button
- $("#left_button").attr("disabled", "disabled").addClass("ui-state-disabled");
- $("#right_button").attr("disabled", "disabled").addClass("ui-state-disabled");
- }
- },
- // This function will set the ULs width
- _get_bar_width: function() {
- // Rest the bar width
- settings.bar_width = 0;
- // Loop through the UL LI tags
- this.element.find(".ui-tabs-nav:first li").each(function() {
- // Add the outWidth of the LI to the bar_width varible
- settings.bar_width += $(this).outerWidth(true);
- });
- // This line fixes any wrapping issue that are caused by the first two tabs
- settings.bar_width = (settings.bar_width < $('#tabs_container').width() - 5) ? $('#tabs_container').width() - 5 : settings.bar_width;
- // Return the width
- return settings.bar_width;
- }
Attachments:
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 6 posts
- Users browsing this forum: ScottG and 251 guests
- You cannot post new topics in this forum
- You cannot reply to topics in this forum
- You cannot edit your posts in this forum
- You cannot delete your posts in this forum
- You cannot post attachments in this forum
