forked from niko/Khan-Shatyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.khan-shatyr.min.js
20 lines (20 loc) · 2.2 KB
/
jquery.khan-shatyr.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Khan Shatyr Minified JS ("Royal Marquee") (see http://en.wikipedia.org/wiki/Khan_Shatyr_Entertainment_Center).
// Author: Kai Himken
// Forked from: https://github.com/niko/Khan-Shatyr
// License: MIT
//
// Works pretty much like a marqee tag, but smoother. Uses jQuery animation for that.
//
// Options:
// * pause: The pause when changing the direction. Defaults to 300.
// * delay: The duration for the animation (aka "speed"). Defaults to 2000.
// * max_kerning: Try to fit content up to this kerning. Defaults to -0.07.
// * easing: Animation easing function. Defaults to 'linear'.
//
// Features:
// * Doesn't scroll content that already fits.
// * Adjustable pause when changing direction.
// * Tries to fit content by reducing the fonts kerning.
// * Detects content changes and reinits the scroller.
//
!function(n){var t;n(window).resize(function(){t&&window.clearTimeout(t),t=window.setTimeout(function(){n(window).trigger("reinit_khan_shatyr")},1e3)});var r={overflowAmount:function(n){return parseFloat(n.contents().width())-parseFloat(n.width())},condenseToFit:function(n,t){for(var r=0;r>=t;){if(n.css("letter-spacing",r+"em"),this.overflowAmount(n)<=0)return null;r-=.003}return n.css("letter-spacing","0em"),this.overflowAmount(n)},scroll:function(n,t,r,e,i){var a=n.css("marign-left");""==a&&(a="0px");var o=function(){n.attr("scrolling")&&window.setTimeout(function(){n.stop(!0),n.animate({"margin-left":-t},r,i,s)},e)},s=function(){window.setTimeout(function(){n.stop(!0),n.animate({"margin-left":a},r,i,o)},e)};o()},init:function(t,r){var e=this;t.attr("khan_shatyr_checker")||(n(window).bind("reinit_khan_shatyr",function(){e.init(t,r)}),t.attr("khan_shatyr_checker",setInterval(function(){1!=t.find("span.khan_shatyr_scroller").length&&e.init(t,r)},1e3))),0==t.find("span.khan_shatyr_scroller").length&&t.wrapInner('<span class="khan_shatyr_scroller"></span>');var i=t.find("span.khan_shatyr_scroller");i.attr("scrolling",!0);var a=this.condenseToFit(t,r.max_kerning);null!=a?e.scroll(i,a,r.delay,r.pause,r.easing):i.removeAttr("scrolling")}};n.fn.khanShatyr=function(t){var e=n.extend({pause:300,delay:2e3,max_kerning:-.05,easing:"linear"},t);return this.each(function(t,i){r.init(n(i),e)})}}(jQuery);