Skip to content

Commit

Permalink
Merge pull request wmh#6 from Rwing/master
Browse files Browse the repository at this point in the history
allow use other list element, like 'dl dt dd'
  • Loading branch information
wmh committed Dec 3, 2013
2 parents ea5a56d + 5f1bf13 commit a7d1d77
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions jquery.scrollbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ $.fn.scrollbox = function(config) {
autoPlay: true,
onMouseOverPause: true,
paused: false,
queue: null
queue: null,
listElement: 'ul',
listItemElement:'li'
};
config = $.extend(defConfig, config);
config.scrollOffset = config.direction === 'vertical' ? 'scrollTop' : 'scrollLeft';
Expand All @@ -46,7 +48,7 @@ $.fn.scrollbox = function(config) {
container.bind('mouseover', function() { paused = true; });
container.bind('mouseout', function() { paused = false; });
}
containerUL = container.children('ul:first-child');
containerUL = container.children(config.listElement + ':first-child');

scrollForward = function() {
if (paused) {
Expand All @@ -58,7 +60,7 @@ $.fn.scrollbox = function(config) {
scrollDistance,
theStep;

curLi = containerUL.children('li:first-child');
curLi = containerUL.children(config.listItemElement + ':first-child');

scrollDistance = config.distance !== 'auto' ? config.distance :
config.direction === 'vertical' ? curLi.outerHeight(true) : curLi.outerWidth(true);
Expand All @@ -74,11 +76,11 @@ $.fn.scrollbox = function(config) {

if (newScrollOffset >= scrollDistance) {
for (i = 0; i < config.switchItems; i++) {
if (config.queue && config.queue.find('li').length > 0) {
containerUL.append(config.queue.find('li')[0]);
containerUL.children('li:first-child').remove();
if (config.queue && config.queue.find(config.listItemElement).length > 0) {
containerUL.append(config.queue.find(config.listItemElement)[0]);
containerUL.children(config.listItemElement + ':first-child').remove();
} else {
containerUL.append(containerUL.children('li:first-child'));
containerUL.append(containerUL.children(config.listItemElement + ':first-child'));
}
}
container[0][config.scrollOffset] = 0;
Expand All @@ -105,12 +107,12 @@ $.fn.scrollbox = function(config) {

// init
if (container[0][config.scrollOffset] === 0) {
liLen = containerUL.children('li').length;
liLen = containerUL.children(config.listItemElement).length;
for (i = 0; i < config.switchItems; i++) {
containerUL.children('li:last-child').insertBefore(containerUL.children('li:first-child'));
containerUL.children(config.listItemElement + ':last-child').insertBefore(containerUL.children(config.listItemElement+':first-child'));
}

curLi = containerUL.children('li:first-child');
curLi = containerUL.children(config.listItemElement + ':first-child');
scrollDistance = config.distance !== 'auto' ?
config.distance :
config.direction === 'vertical' ? curLi.height() : curLi.width();
Expand Down Expand Up @@ -175,4 +177,4 @@ $.fn.scrollbox = function(config) {
});
};

}(jQuery));
}(jQuery));

0 comments on commit a7d1d77

Please sign in to comment.