Last active
January 17, 2022 05:09
-
-
Save michaeljohnson/4674932 to your computer and use it in GitHub Desktop.
Extend Carousel from Twitter Bootstrap (bootstrap-carousel.js) with js fallback for browsers without css3 transition support. See @barryvdh https://github.com/Barryvdh/bootstrap/commit/8b294f0c0184eb7111ef6da6046d4d1f33ea7ba3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var extensionMethods = { | |
slide: function (type, next) { | |
if(!$.support.transition && this.$element.hasClass('slide')) { | |
this.$element.find('.item').stop(true, true); //Finish animation and jump to end. | |
} | |
var $active = this.$element.find('.active') | |
, $next = next || $active[type]() | |
, isCycling = this.interval | |
, direction = type == 'next' ? 'left' : 'right' | |
, fallback = type == 'next' ? 'first' : 'last' | |
, that = this | |
, e = $.Event('slide') | |
this.sliding = true | |
isCycling && this.pause() | |
$next = $next.length ? $next : this.$element.find('.item')[fallback]() | |
if ($next.hasClass('active')) return | |
if ($.support.transition && this.$element.hasClass('slide')) { | |
this.$element.trigger(e) | |
if (e.isDefaultPrevented()) return | |
$next.addClass(type) | |
$next[0].offsetWidth // force reflow | |
$active.addClass(direction) | |
$next.addClass(direction) | |
this.$element.one($.support.transition.end, function () { | |
$next.removeClass([type, direction].join(' ')).addClass('active') | |
$active.removeClass(['active', direction].join(' ')) | |
that.sliding = false | |
setTimeout(function () { that.$element.trigger('slid') }, 0) | |
}) | |
}else if(!$.support.transition && this.$element.hasClass('slide')) { | |
this.$element.trigger(e) | |
if (e.isDefaultPrevented()) return | |
$active.animate({left: (direction == 'right' ? '100%' : '-100%')}, 600, function(){ | |
$active.removeClass('active') | |
that.sliding = false | |
setTimeout(function () { that.$element.trigger('slid') }, 0) | |
}) | |
$next.addClass(type).css({left: (direction == 'right' ? '-100%' : '100%')}).animate({left: '0'}, 600, function(){ | |
$next.removeClass(type).addClass('active') | |
}) | |
} else { | |
this.$element.trigger(e) | |
if (e.isDefaultPrevented()) return | |
$active.removeClass('active') | |
$next.addClass('active') | |
this.sliding = false | |
this.$element.trigger('slid') | |
} | |
isCycling && this.cycle() | |
return this | |
} | |
}; | |
$.extend(true, $[ "fn" ][ "carousel" ][ "Constructor" ].prototype, extensionMethods); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to change ... .animate({ left: '0%' } , 600 .... on line 44 for work it correctly on IE