diff --git a/ES6-kute.js b/ES6-kute.js new file mode 100644 index 0000000..77be8ac --- /dev/null +++ b/ES6-kute.js @@ -0,0 +1,837 @@ +/* KUTE.js - The Light Tweening Engine + * by dnp_theme + * Licensed under MIT-License + */ +(((root, factory) => { + if (typeof define === 'function' && define.amd) { + define([], factory); // AMD. Register as an anonymous module. + } else if (typeof exports == 'object') { + module.exports = factory(); // Node, not strict CommonJS + } else { + root.KUTE = factory(); + } +})(this, () => { + // set a custom scope for KUTE.js + const g = typeof global !== 'undefined' ? global : window; // tick must be null!! + + const time = g.performance; + let tweens = []; + let tick = null; + + //supported properties + const // colors 'hex', 'rgb', 'rgba' -- #fff / rgb(0,0,0) / rgba(0,0,0,0) + _colors = ['color', 'backgroundColor']; //all properties default values + + const // dimensions / box model + _boxModel = ['top', 'left', 'width', 'height']; + + const // transform + _transform = ['translate3d', 'translateX', 'translateY', 'translateZ', 'rotate', 'translate', 'rotateX', 'rotateY', 'rotateZ', 'skewX', 'skewY', 'scale']; + + const //scroll, it has no default value, it's calculated on tween start + _scroll = ['scroll']; + + const // opacity + _opacity = ['opacity']; + + const _all = _colors.concat( _opacity, _boxModel, _transform); + const al = _all.length; + const _defaults = {}; + + //populate default values object + for ( let i=0; i { + //returns browser prefix + let div = document.createElement('div'); + + var i = 0; + const pf = ['Moz', 'moz', 'Webkit', 'webkit', 'O', 'o', 'Ms', 'ms']; + const s = ['MozTransform', 'mozTransform', 'WebkitTransform', 'webkitTransform', 'OTransform', 'oTransform', 'MsTransform', 'msTransform']; + for (const i = 0, pl = pf.length; i < pl; i++) { if (s[i] in div.style) { return pf[i]; } } + div = null; + }; + + const property = p => { // returns prefixed property | property + const r = (!(p in document.body.style)) ? true : false, f = getPrefix(); // is prefix required for property | prefix + return r ? f + (p.charAt(0).toUpperCase() + p.slice(1)) : p; + }; + + const selector = (el, multi) => { // a public selector utility + let nl; + if (multi){ + nl = el instanceof Object || typeof el === 'object' ? el : document.querySelectorAll(el); + } else { + nl = typeof el === 'object' ? el + : /^#/.test(el) ? document.getElementById(el.replace('#','')) : document.querySelector(el); + } + if (nl === null && el !== 'window') throw new TypeError(`Element not found or incorrect selector: ${el}`); + return nl; + }; + + const radToDeg = a => a*180/Math.PI; + + const trueDimension = (d, p) => { + //true dimension returns { v = value, u = unit } + const x = parseInt(d) || 0; + + const mu = ['px','%','deg','rad','em','rem','vh','vw']; + let y; + for (let i=0, l = mu.length; i { // replace transparent and transform any color to rgba()/rgb() + if (/rgb|rgba/.test(v)) { // first check if it's a rgb string + const vrgb = v.replace(/\s|\)/,'').split('(')[1].split(','), y = vrgb[3] ? vrgb[3] : null; + if (!y) { + return { r: parseInt(vrgb[0]), g: parseInt(vrgb[1]), b: parseInt(vrgb[2]) }; + } else { + return { r: parseInt(vrgb[0]), g: parseInt(vrgb[1]), b: parseInt(vrgb[2]), a: parseFloat(y) }; + } + } else if (/^#/.test(v)) { + const fromHex = hexToRGB(v); return { r: fromHex.r, g: fromHex.g, b: fromHex.b }; + } else if (/transparent|none|initial|inherit/.test(v)) { + return { r: 0, g: 0, b: 0, a: 0 }; + } else if (!/^#|^rgb/.test(v) ) { // maybe we can check for web safe colors + const h = document.getElementsByTagName('head')[0]; h.style.color = v; + let webColor = g.getComputedStyle(h,null).color; webColor = /rgb/.test(webColor) ? webColor.replace(/[^\d,]/g, '').split(',') : [0,0,0]; + h.style.color = ''; return { r: parseInt(webColor[0]), g: parseInt(webColor[1]), b: parseInt(webColor[2]) }; + } + }; + + const rgbToHex = (r, g, b) => // transform rgb to hex or vice-versa | webkit browsers ignore HEX, always use RGB/RGBA + `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`; + + const hexToRGB = hex => { + const shr = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") + hex = hex.replace(shr, (m, r, g, b) => r + r + g + g + b + b); + const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); + return result ? { + r: parseInt(result[1], 16), + g: parseInt(result[2], 16), + b: parseInt(result[3], 16) + } : null; + }; + + const getInlineStyle = (el, p) => { // get transform style for element from cssText for .to() method, the sp is for transform property + if (!el) return; // if the scroll applies to `window` it returns as it has no styling + const //the cssText + css = el.style.cssText.replace(/\s/g,'').split(';'), + trsf = {}; //the transform object + // if we have any inline style in the cssText attribute, usually it has higher priority + for ( let i=0, csl = css.length; i { // get computed style property for element for .to() method + const styleAttribute = el.style, + computedStyle = g.getComputedStyle(el,null) || el.currentStyle, + //the computed style | prefixed property + pp = property(p), + styleValue = styleAttribute[p] && !/auto|initial|none|unset/.test(styleAttribute[p]) ? styleAttribute[p] : computedStyle[pp]; // s the property style value + if ( p !== 'transform' && (pp in computedStyle || pp in styleAttribute) ) { + if ( styleValue ){ + if (pp==='filter') { // handle IE8 opacity + const filterValue = parseInt(styleValue.split('=')[1].replace(')','')); + return parseFloat(filterValue/100); + } else { + return styleValue; + } + } else { + return _defaults[p]; + } + } + }; + + const //more internals + getAll = () => tweens; + + const removeAll = () => { tweens = []; }; + const add = tw => { tweens.push(tw); }; + const remove = tw => { const i = tweens.indexOf(tw); if (i !== -1) { tweens.splice(i, 1); }}; + const stop = () => { if (tick) { _cancelAnimationFrame(tick); tick = null; } }; + + const // support Touch? + canTouch = ('ontouchstart' in g || navigator && navigator.msMaxTouchPoints) || false; + + const touchOrWheel = canTouch ? 'touchstart' : 'mousewheel'; + + const //events to prevent on scroll + mouseEnter = 'mouseenter'; + + const _requestAnimationFrame = g.requestAnimationFrame || g.webkitRequestAnimationFrame || (c => setTimeout(c, 16)); + const _cancelAnimationFrame = g.cancelAnimationFrame || g.webkitCancelRequestAnimationFrame || (c => clearTimeout(c)); + const transformProperty = property('transform'); + + const //true scroll container + body = document.body; + + const html = document.getElementsByTagName('HTML')[0]; + const scrollContainer = navigator && /webkit/i.test(navigator.userAgent) || document.compatMode == 'BackCompat' ? body : html; + const isIE = navigator && (new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})").exec(navigator.userAgent) !== null) ? parseFloat( RegExp.$1 ) : false; + + const // check IE8/IE + isIE8 = isIE === 8; + + const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); + + // KUTE.js INTERPOLATORS + const interpolate = g.Interpolate = {}; + + // core easing functions + + const number = interpolate.number = (a, b, v) => { // number1, number2, progress + a = +a; b -= a; return a + b * v; + }; + + const unit = interpolate.unit = (a, b, u, v) => { // number1, number2, unit, progress + a = +a; b -= a; return ( a + b * v ) + u; + }; + + const color = interpolate.color = (a, b, v, h) => { + // rgba1, rgba2, progress, convertToHex(true/false) + const _c = {}; + + let c; + const n = number; + const ep = ')'; + const cm =','; + const r = 'rgb('; + const ra = 'rgba('; + for (c in b) { _c[c] = c !== 'a' ? (number(a[c],b[c],v)>>0 || 0) : (a[c] && b[c]) ? (number(a[c],b[c],v) * 100 >> 0 )/100 : null; } + return h ? rgbToHex( _c.r, _c.g, _c.b ) : !_c.a ? r + _c.r + cm + _c.g + cm + _c.b + ep : ra + _c.r + cm + _c.g + cm + _c.b + cm + _c.a + ep; + }; + + const translate = interpolate.translate = isMobile ? (a, b, u, v) => { + const translation = {}; + for (const ax in b){ + translation[ax] = ( a[ax]===b[ax] ? b[ax] : (a[ax] + ( b[ax] - a[ax] ) * v ) >> 0 ) + u; + } + return translation.x||translation.y ? `translate(${translation.x},${translation.y})` : + `translate3d(${translation.translateX},${translation.translateY},${translation.translateZ})`; + } : (a, b, u, v) => { + const translation = {}; + for (const ax in b){ + translation[ax] = ( a[ax]===b[ax] ? b[ax] : ( (a[ax] + ( b[ax] - a[ax] ) * v ) * 100 >> 0 ) / 100 ) + u; + } + return translation.x||translation.y ? `translate(${translation.x},${translation.y})` : + `translate3d(${translation.translateX},${translation.translateY},${translation.translateZ})`; + }; + + const rotate = interpolate.rotate = (a, b, u, v) => { + const rotation = {}; + for ( const rx in b ){ + rotation[rx] = rx === 'z' ? (`rotate(${((a[rx] + (b[rx] - a[rx]) * v) * 100 >> 0 ) / 100}${u})`) + : (`${rx}(${((a[rx] + (b[rx] - a[rx]) * v) * 100 >> 0 ) / 100}${u})`); + } + return rotation.z ? rotation.z : (rotation.rotateX||'') + (rotation.rotateY||'') + (rotation.rotateZ||''); + }; + + const skew = interpolate.skew = (a, b, u, v) => { + const skewProp = {}; + for ( const sx in b ){ + skewProp[sx] = `${sx}(${((a[sx] + (b[sx] - a[sx]) * v) * 10 >> 0) / 10}${u})`; + } + return (skewProp.skewX||'') + (skewProp.skewY||''); + }; + + const scale = interpolate.scale = (a, b, v) => `scale(${((a + (b - a) * v) * 1000 >> 0 ) / 1000})`; + + const // KUTE.js DOM update functions + DOM = {}; + + const ticker = t => { + let i = 0; + while ( i < tweens.length ) { + if ( update.call(tweens[i],t) ) { + i++; + } else { + tweens.splice(i, 1); + } + } + tick = _requestAnimationFrame(ticker); + }; + + const update = function(t=time.now()) { + if ( t < this._startTime && this.playing ) { return true; } + + const elapsed = Math.min(( t - this._startTime ) / this.options.duration, 1), progress = this.options.easing(elapsed); // calculate progress + + for (const p in this.valuesEnd){ DOM[p](this.element,p,this.valuesStart[p],this.valuesEnd[p],progress,this.options); } //render the CSS update + + if (this.options.update) { this.options.update.call(); } // fire the updateCallback + + if (elapsed === 1) { + if (this.options.repeat > 0) { + if ( isFinite(this.options.repeat ) ) { this.options.repeat--; } + + if (this.options.yoyo) { // handle yoyo + this.reversed = !this.reversed; + reverse.call(this); + } + + this._startTime = (this.options.yoyo && !this.reversed) ? t + this.options.repeatDelay : t; //set the right time for delay + return true; + } else { + + if (this.options.complete) { this.options.complete.call(); } + + scrollOut.call(this); // unbind preventing scroll when scroll tween finished + + for (let i = 0, ctl = this.options.chain.length; i < ctl; i++) { // start animating chained tweens + this.options.chain[i].start(); + } + + //stop ticking when finished + close.call(this); + } + return false; + } + return true; + }; + + const // applies the transform origin and perspective + perspective = function () { + const el = this.element, ops = this.options; + if ( ops.perspective !== undefined && transformProperty in this.valuesEnd ) { // element perspective + this.valuesStart[transformProperty]['perspective'] = this.valuesEnd[transformProperty]['perspective']; + } + // element transform origin / we filter it out for svgTransform to fix the Firefox transformOrigin bug https://bugzilla.mozilla.org/show_bug.cgi?id=923193 + if ( ops.transformOrigin !== undefined && (!('svgTransform' in this.valuesEnd)) ) { el.style[property('transformOrigin')] = ops.transformOrigin; } // set transformOrigin for CSS3 transforms only + if ( ops.perspectiveOrigin !== undefined ) { el.style[property('perspectiveOrigin')] = ops.perspectiveOrigin; } // element perspective origin + if ( ops.parentPerspective !== undefined ) { el.parentNode.style[property('perspective')] = `${ops.parentPerspective}px`; } // parent perspective + if ( ops.parentPerspectiveOrigin !== undefined ) { el.parentNode.style[property('perspectiveOrigin')] = ops.parentPerspectiveOrigin; } // parent perspective origin + }; + + const // plugin connector objects + // check current property value when .to() method is used + prepareStart = {}; + + const // checks for differences between start and end value, try to make sure start unit and end unit are same as well as consistent, stack transforms, process SVG paths + crossCheck = {}; + + const // parse properties object + // string parsing and property specific value processing + parseProperty = { // we already start working on core supported properties + boxModel(p, v) { + if (!(p in DOM)){ + DOM[p] = (l, p, a, b, v) => { + l.style[p] = `${v > 0.99 || v < 0.01 ? ((number(a,b,v)*10)>>0)/10 : (number(a,b,v) ) >> 0}px`; + } + } + const boxValue = trueDimension(v); + return boxValue.u === '%' ? boxValue.v * this.element.offsetWidth / 100 : boxValue.v; + }, + transform(p, v) { + if (!(transformProperty in DOM)) { + DOM[transformProperty] = (l, p, a, b, v, o) => { + l.style[p] = (a.perspective||'') + + ('translate' in a ? translate(a.translate,b.translate,'px',v):'') + + ('rotate' in a ? rotate(a.rotate,b.rotate,'deg',v):'') + + ('skew' in a ? skew(a.skew,b.skew,'deg',v):'') + + ('scale' in a ? scale(a.scale,b.scale,v):''); + } + } + + // process each transform property + if (/translate/.test(p)) { + if (p === 'translate3d') { + const t3d = v.split(','), t3d0 = trueDimension(t3d[0]), t3d1 = trueDimension(t3d[1], t3d2 = trueDimension(t3d[2])); + return { + translateX : t3d0.u === '%' ? (t3d0.v * this.element.offsetWidth / 100) : t3d0.v, + translateY : t3d1.u === '%' ? (t3d1.v * this.element.offsetHeight / 100) : t3d1.v, + translateZ : t3d2.u === '%' ? (t3d2.v * (this.element.offsetHeight + this.element.offsetWidth) / 200) : t3d2.v // to be changed with something like element and/or parent perspective + }; + } else if (/^translate(?:[XYZ])$/.test(p)) { + const t1d = trueDimension(v), percentOffset = /X/.test(p) ? this.element.offsetWidth / 100 : /Y/.test(p) ? this.element.offsetHeight / 100 : (this.element.offsetWidth+this.element.offsetHeight) / 200; + + return t1d.u === '%' ? (t1d.v * percentOffset) : t1d.v; + } else if (p === 'translate') { + const tv = typeof v === 'string' ? v.split(',') : v; + const t2d = {}; + let t2dv; + const t2d0 = trueDimension(tv[0]); + const t2d1 = tv.length ? trueDimension(tv[1]) : {v: 0, u: 'px'}; + if (tv instanceof Array) { + t2d.x = t2d0.u === '%' ? (t2d0.v * this.element.offsetWidth / 100) : t2d0.v, + t2d.y = t2d1.u === '%' ? (t2d1.v * this.element.offsetHeight / 100) : t2d1.v + } else { + t2dv = trueDimension(tv); + t2d.x = t2dv.u === '%' ? (t2dv.v * this.element.offsetWidth / 100) : t2dv.v, + t2d.y = 0 + } + + return t2d; + } + } else if (/rotate|skew/.test(p)) { + if (/^rotate(?:[XYZ])$|skew(?:[XY])$/.test(p)) { + const r3d = trueDimension(v,true); + return r3d.u === 'rad' ? radToDeg(r3d.v) : r3d.v; + } else if (p === 'rotate') { + const r2d = {}, r2dv = trueDimension(v,true); + r2d.z = r2dv.u === 'rad' ? radToDeg(r2dv.v) : r2dv.v; + return r2d; + } + } else if (p === 'scale') { + return parseFloat(v); // this must be parseFloat(v) + } + }, + unitless(p, v) { // scroll | opacity + if (/scroll/.test(p) && !(p in DOM) ){ + DOM[p] = (l, p, a, b, v) => { + l.scrollTop = (number(a,b,v))>>0; + }; + } else if (p === 'opacity') { + if (!(p in DOM)) { + if (isIE8) { + DOM[p] = (l, p, a, b, v) => { + const st = "alpha(opacity=", ep = ')'; + l.style.filter = st + ((number(a,b,v) * 100)>>0) + ep; + }; + } else { + DOM[p] = (l, p, a, b, v) => { + l.style.opacity = ((number(a,b,v) * 100)>>0)/100; + }; + } + } + } + return parseFloat(v); + }, + colors(p, v) { // colors + if (!(p in DOM)) { + DOM[p] = (l, p, a, b, v, o) => { + l.style[p] = color(a,b,v,o.keepHex); + }; + } + return trueColor(v); + } + }; + + const // process properties for endValues and startValues or one of them + preparePropertiesObject = function(obj, fn) { // this, props object, type: start/end + const element = this.element, propertiesObject = fn === 'start' ? this.valuesStart : this.valuesEnd, skewObject = {}, rotateObject = {}, translateObject = {}, transformObject = {}; + + for (const x in obj) { + if (_transform.includes(x)) { // transform object gets built here + if ( /^translate(?:[XYZ]|3d)$/.test(x) ) { //process translate3d + const ta = ['X', 'Y', 'Z']; //coordinates // translate[x] = pp(x, obj[x]); + + for (let f = 0; f < 3; f++) { + const a = ta[f]; + if ( /3d/.test(x) ) { + translateObject[`translate${a}`] = parseProperty.transform.call(this,`translate${a}`, obj[x][f]); + } else { + translateObject[`translate${a}`] = (`translate${a}` in obj) ? parseProperty.transform.call(this,`translate${a}`, obj[`translate${a}`]) : 0; + } + } + transformObject['translate'] = translateObject; + } else if ( /^rotate(?:[XYZ])$|^skew(?:[XY])$/.test(x) ) { //process rotation/skew + const ap = /rotate/.test(x) ? 'rotate' : 'skew', ra = ['X', 'Y', 'Z'], rtp = ap === 'rotate' ? rotateObject : skewObject; + for (let r = 0; r < 3; r++) { + const v = ra[r]; + if ( obj[ap+v] !== undefined && x !== 'skewZ' ) { + rtp[ap+v] = parseProperty.transform.call(this,ap+v, obj[ap+v]); + } + } + transformObject[ap] = rtp; + } else if ( /(rotate|translate|scale)$/.test(x) ) { //process 2d translation / rotation + transformObject[x] = parseProperty.transform.call(this, x, obj[x]); + } + propertiesObject[transformProperty] = transformObject; + } else { + if ( _boxModel.includes(x) ) { + propertiesObject[x] = parseProperty.boxModel.call(this,x,obj[x]); + } else if (_opacity.includes(x) || x === 'scroll') { + propertiesObject[x] = parseProperty.unitless.call(this,x,obj[x]); + } else if (_colors.includes(x)) { + propertiesObject[x] = parseProperty.colors.call(this,x,obj[x]); + } else if (x in parseProperty) { // or any other property from css/ attr / svg / third party plugins + propertiesObject[x] = parseProperty[x].call(this,x,obj[x]); + } + } + } + }; + + const reverse = function () { + if (this.options.yoyo) { + for (const p in this.valuesEnd) { + const tmp = this.valuesRepeat[p]; + this.valuesRepeat[p] = this.valuesEnd[p]; + this.valuesEnd[p] = tmp; + this.valuesStart[p] = this.valuesRepeat[p]; + } + } + }; + + const close = function () { // when animation is finished reset repeat, yoyo&reversed tweens + if (this.repeat > 0) { this.options.repeat = this.repeat; } + if (this.options.yoyo && this.reversed===true) { reverse.call(this); this.reversed = false; } + this.playing = false; + + setTimeout(() => { if (!tweens.length) { stop(); } }, 48); // when all animations are finished, stop ticking after ~3 frames + }; + + const preventScroll = e => { // prevent mousewheel or touch events while tweening scroll + const data = document.body.getAttribute('data-tweening'); + if (data && data === 'scroll') { e.preventDefault(); } + }; + + const scrollOut = function(){ //prevent scroll when tweening scroll + if ( 'scroll' in this.valuesEnd && document.body.getAttribute('data-tweening')) { + document.removeEventListener(touchOrWheel, preventScroll, false); + document.removeEventListener(mouseEnter, preventScroll, false); + document.body.removeAttribute('data-tweening'); + } + }; + + const scrollIn = function(){ + if ( 'scroll' in this.valuesEnd && !document.body.getAttribute('data-tweening')) { + document.addEventListener(touchOrWheel, preventScroll, false); + document.addEventListener(mouseEnter, preventScroll, false); + document.body.setAttribute('data-tweening', 'scroll'); + } + }; + + const processEasing = fn => { //process easing function + if ( typeof fn === 'function') { + return fn; + } else if ( typeof fn === 'string' ) { + return easing[fn]; // regular Robert Penner Easing Functions + } + }; + + const getStartValues = function () { // stack transform props for .to() chains + const startValues = {}, currentStyle = getInlineStyle(this.element,'transform'), deg = ['rotate','skew'], ax = ['X','Y','Z']; + + for (var p in this.valuesStart){ + if ( _transform.includes(p) ) { + const r2d = (/(rotate|translate|scale)$/.test(p)); + if ( /translate/.test(p) && p !== 'translate' ) { + startValues['translate3d'] = currentStyle['translate3d'] || _defaults[p]; + } else if ( r2d ) { // 2d transforms + startValues[p] = currentStyle[p] || _defaults[p]; + } else if ( !r2d && /rotate|skew/.test(p) ) { // all angles + for (var d=0; d<2; d++) { + for (let a = 0; a<3; a++) { + const s = deg[d]+ax[a]; + if (_transform.includes(s) && (s in this.valuesStart) ) { startValues[s] = currentStyle[s] || _defaults[s]; } + } + } + } + } else { + if ( p !== 'scroll' ) { + if (p === 'opacity' && isIE8 ) { // handle IE8 opacity + const currentOpacity = getCurrentStyle(this.element,'filter'); + startValues['opacity'] = typeof currentOpacity === 'number' ? currentOpacity : _defaults['opacity']; + } else { + if ( _all.includes(p) ) { + startValues[p] = getCurrentStyle(this.element,p) || d[p]; + } else { // plugins register here + startValues[p] = p in prepareStart ? prepareStart[p].call(this,p,this.valuesStart[p]) : 0; + } + } + } else { + startValues[p] = this.element === scrollContainer ? (g.pageYOffset || scrollContainer.scrollTop) : this.element.scrollTop; + } + } + } + for ( var p in currentStyle ){ // also add to startValues values from previous tweens + if ( _transform.includes(p) && (!( p in this.valuesStart )) ) { + startValues[p] = currentStyle[p] || _defaults[p]; + } + } + + this.valuesStart = {}; + preparePropertiesObject.call(this,startValues,'start'); + + if ( transformProperty in this.valuesEnd ) { // let's stack transform + for ( const sp in this.valuesStart[transformProperty]) { // sp is the object corresponding to the transform function objects translate / rotate / skew / scale + if ( sp !== 'perspective') { + if ( typeof this.valuesStart[transformProperty][sp] === 'object' ) { + for ( const spp in this.valuesStart[transformProperty][sp] ) { // 3rd level + if ( typeof this.valuesEnd[transformProperty][sp] === 'undefined' ) { this.valuesEnd[transformProperty][sp] = {}; } + if ( typeof this.valuesStart[transformProperty][sp][spp] === 'number' && typeof this.valuesEnd[transformProperty][sp][spp] === 'undefined' ) { + this.valuesEnd[transformProperty][sp][spp] = this.valuesStart[transformProperty][sp][spp]; + } + } + } else if ( typeof this.valuesStart[transformProperty][sp] === 'number' ) { + if ( typeof this.valuesEnd[transformProperty][sp] === 'undefined' ) { // scale + this.valuesEnd[transformProperty][sp] = this.valuesStart[transformProperty][sp]; + } + } + } + } + } + }; + + var easing = g.Easing = {}; + easing.linear = t => t; + easing.easingSinusoidalIn = t => -Math.cos(t * Math.PI / 2) + 1; + easing.easingSinusoidalOut = t => Math.sin(t * Math.PI / 2); + easing.easingSinusoidalInOut = t => -0.5 * (Math.cos(Math.PI * t) - 1); + easing.easingQuadraticIn = t => t*t; + easing.easingQuadraticOut = t => t*(2-t); + easing.easingQuadraticInOut = t => t<.5 ? 2*t*t : -1+(4-2*t)*t; + easing.easingCubicIn = t => t*t*t; + easing.easingCubicOut = t => (--t)*t*t+1; + easing.easingCubicInOut = t => t<.5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1; + easing.easingQuarticIn = t => t*t*t*t; + easing.easingQuarticOut = t => 1-(--t)*t*t*t; + easing.easingQuarticInOut = t => t<.5 ? 8*t*t*t*t : 1-8*(--t)*t*t*t; + easing.easingQuinticIn = t => t*t*t*t*t; + easing.easingQuinticOut = t => 1+(--t)*t*t*t*t; + easing.easingQuinticInOut = t => t<.5 ? 16*t*t*t*t*t : 1+16*(--t)*t*t*t*t; + easing.easingCircularIn = t => -(Math.sqrt(1 - (t * t)) - 1); + easing.easingCircularOut = t => Math.sqrt(1 - (t = t - 1) * t); + easing.easingCircularInOut = t => ((t*=2) < 1) ? -0.5 * (Math.sqrt(1 - t * t) - 1) : 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1); + easing.easingExponentialIn = t => 2 ** (10 * (t - 1)) - 0.001; + easing.easingExponentialOut = t => 1 - 2 ** (-10 * t); + easing.easingExponentialInOut = t => (t *= 2) < 1 ? 0.5 * (2 ** (10 * (t - 1))) : 0.5 * (2 - 2 ** (-10 * (t - 1))); + easing.easingBackIn = t => { const s = 1.70158; return t * t * ((s + 1) * t - s); }; + easing.easingBackOut = t => { const s = 1.70158; return --t * t * ((s + 1) * t + s) + 1; }; + easing.easingBackInOut = t => { const s = 1.70158 * 1.525; if ((t *= 2) < 1) return 0.5 * (t * t * ((s + 1) * t - s)); return 0.5 * ((t -= 2) * t * ((s + 1) * t + s) + 2); }; + easing.easingElasticIn = t => { + let s; + let _kea = 0.1; + const _kep = 0.4; + if ( t === 0 ) return 0;if ( t === 1 ) return 1; + if ( !_kea || _kea < 1 ) { _kea = 1; s = _kep / 4; } else s = _kep * Math.asin( 1 / _kea ) / Math.PI * 2; + return - ( _kea * (2 ** (10 * (t -= 1))) * Math.sin( ( t - s ) * Math.PI * 2 / _kep ) ); + }; + easing.easingElasticOut = t => { + let s; + let _kea = 0.1; + const _kep = 0.4; + if ( t === 0 ) return 0;if ( t === 1 ) return 1; + if ( !_kea || _kea < 1 ) { _kea = 1; s = _kep / 4; } else s = _kep * Math.asin( 1 / _kea ) / Math.PI * 2 ; + return ( _kea * (2 ** (- 10 * t)) * Math.sin( ( t - s ) * Math.PI * 2 / _kep ) + 1 ); + }; + easing.easingElasticInOut = t => { + let s; + let _kea = 0.1; + const _kep = 0.4; + if ( t === 0 ) return 0;if ( t === 1 ) return 1; + if ( !_kea || _kea < 1 ) { _kea = 1; s = _kep / 4; } else s = _kep * Math.asin( 1 / _kea ) / Math.PI * 2 ; + if ( ( t *= 2 ) < 1 ) return - 0.5 * ( _kea * (2 ** (10 * (t -= 1))) * Math.sin( ( t - s ) * Math.PI * 2 / _kep ) ); + return _kea * (2 ** (-10 * (t -= 1))) * Math.sin( ( t - s ) * Math.PI * 2 / _kep ) * 0.5 + 1; + }; + easing.easingBounceIn = t => 1 - easing.easingBounceOut( 1 - t ); + easing.easingBounceOut = t => { + if ( t < ( 1 / 2.75 ) ) { return 7.5625 * t * t; } + else if ( t < ( 2 / 2.75 ) ) { return 7.5625 * ( t -= ( 1.5 / 2.75 ) ) * t + 0.75; } + else if ( t < ( 2.5 / 2.75 ) ) { return 7.5625 * ( t -= ( 2.25 / 2.75 ) ) * t + 0.9375; } + else {return 7.5625 * ( t -= ( 2.625 / 2.75 ) ) * t + 0.984375; } + }; + easing.easingBounceInOut = t => { if ( t < 0.5 ) return easing.easingBounceIn( t * 2 ) * 0.5; return easing.easingBounceOut( t * 2 - 1 ) * 0.5 + 0.5;}; + + // single Tween object construct + const Tween = function (targetElement, startObject, endObject, options) { + this.element = 'scroll' in endObject && (targetElement === undefined || targetElement === null) ? scrollContainer : targetElement; // element animation is applied to + + this.playing = false; + this.reversed = false; + this.paused = false; + + this._startTime = null; + this._pauseTime = null; + + this._startFired = false; + this.options = {}; for (const o in options) { this.options[o] = options[o]; } + this.options.rpr = options.rpr || false; // internal option to process inline/computed style at start instead of init true/false + + this.valuesRepeat = {}; // internal valuesRepeat + this.valuesEnd = {}; // valuesEnd + this.valuesStart = {}; // valuesStart + + preparePropertiesObject.call(this,endObject,'end'); // valuesEnd + if ( this.options.rpr ) { this.valuesStart = startObject; } else { preparePropertiesObject.call(this,startObject,'start'); } // valuesStart + + if ( this.options.perspective !== undefined && transformProperty in this.valuesEnd ) { // element transform perspective + const perspectiveString = `perspective(${parseInt(this.options.perspective)}px)`; + this.valuesEnd[transformProperty].perspective = perspectiveString; + } + + for ( const e in this.valuesEnd ) { + if (e in crossCheck && !this.options.rpr) crossCheck[e].call(this); // this is where we do the valuesStart and valuesEnd check for fromTo() method + } + + this.options.chain = []; // chained Tweens + this.options.easing = options.easing && typeof processEasing(options.easing) === 'function' ? processEasing(options.easing) : easing[defaultOptions.easing]; // you can only set a core easing function as default + this.options.repeat = options.repeat || defaultOptions.repeat; + this.options.repeatDelay = options.repeatDelay || defaultOptions.repeatDelay; + this.options.yoyo = options.yoyo || defaultOptions.yoyo; + this.options.duration = options.duration || defaultOptions.duration; // duration option | default + this.options.delay = options.delay || defaultOptions.delay; // delay option | default + + this.repeat = this.options.repeat; // we cache the number of repeats to be able to put it back after all cycles finish + }; + + const // tween control and chain + TweenProto = Tween.prototype = { + // queue tween object to main frame update + start(t) { // move functions that use the ticker outside the prototype to be in the same scope with it + scrollIn.call(this); + + if ( this.options.rpr ) { getStartValues.apply(this); } // on start we reprocess the valuesStart for TO() method + perspective.apply(this); // apply the perspective and transform origin + + for ( const e in this.valuesEnd ) { + if (e in crossCheck && this.options.rpr) crossCheck[e].call(this); // this is where we do the valuesStart and valuesEnd check for to() method + this.valuesRepeat[e] = this.valuesStart[e]; + } + + // now it's a good time to start + tweens.push(this); + this.playing = true; + this.paused = false; + this._startFired = false; + this._startTime = t || time.now(); + this._startTime += this.options.delay; + + if (!this._startFired) { + if (this.options.start) { this.options.start.call(); } + this._startFired = true; + } + !tick && ticker(); + return this; + }, + play() { + if (this.paused && this.playing) { + this.paused = false; + if (this.options.resume) { this.options.resume.call(); } + this._startTime += time.now() - this._pauseTime; + add(this); + !tick && ticker(); // restart ticking if stopped + } + return this; + }, + resume() { return this.play(); }, + pause() { + if (!this.paused && this.playing) { + remove(this); + this.paused = true; + this._pauseTime = time.now(); + if (this.options.pause) { this.options.pause.call(); } + } + return this; + }, + stop() { + if (!this.paused && this.playing) { + remove(this); + this.playing = false; + this.paused = false; + scrollOut.call(this); + + if (this.options.stop) { this.options.stop.call(); } + this.stopChainedTweens(); + close.call(this); + } + return this; + }, + chain() { this.options.chain = arguments; return this; }, + stopChainedTweens() { + for (let i = 0, ctl = this.options.chain.length; i < ctl; i++) { + this.options.chain[i].stop(); + } + } + }; + + const // the multi elements Tween constructs + TweensTO = function (els, vE, o) { // .to + this.tweens = []; const options = []; + for ( let i = 0, tl = els.length; i < tl; i++ ) { + options[i] = o || {}; o.delay = o.delay || defaultOptions.delay; + options[i].delay = i>0 ? o.delay + (o.offset||defaultOptions.offset) : o.delay; + this.tweens.push( to(els[i], vE, options[i]) ); + } + }; + + const TweensFT = function (els, vS, vE, o) { // .fromTo + this.tweens = []; const options = []; + for ( let i = 0, l = els.length; i < l; i++ ) { + options[i] = o || {}; o.delay = o.delay || defaultOptions.delay; + options[i].delay = i>0 ? o.delay + (o.offset||defaultOptions.offset) : o.delay; + this.tweens.push( fromTo(els[i], vS, vE, options[i]) ); + } + }; + + const ws = TweensTO.prototype = TweensFT.prototype = { + start(t=time.now()) { + for ( let i = 0, tl = this.tweens.length; i < tl; i++ ) { + this.tweens[i].start(t); + } + return this; + }, + stop() { for ( let i = 0, tl = this.tweens.length; i < tl; i++ ) { this.tweens[i].stop(); } return this; }, + pause() { for ( let i = 0, tl = this.tweens.length; i < tl; i++ ) { this.tweens[i].pause(); } return this; }, + chain() { this.tweens[this.tweens.length-1].options.chain = arguments; return this; }, + play() { for ( let i = 0, tl = this.tweens.length; i < tl; i++ ) { this.tweens[i].play(); } return this; }, + resume() {return this.play()} + }; + + const // main methods + to = (element, endObject, options) => { + options = options || {}; options.rpr = true; + return new Tween(selector(element), endObject, endObject, options); + }; + + const fromTo = (element, startObject, endObject, options) => { + options = options || {}; + return new Tween(selector(element), startObject, endObject, options); + }; + + const // multiple elements tweening + allTo = (elements, endObject, options) => new TweensTO(selector(elements,true), endObject, options); + + const allFromTo = (elements, f, endObject, options) => new TweensFT(selector(elements,true), f, endObject, options); + + return { // export core methods to public for plugins + property, getPrefix, selector, processEasing, // utils + defaultOptions, // default tween options since 1.6.1 + to, fromTo, allTo, allFromTo, // main methods + ticker, tick, tweens, update, dom : DOM, // update + parseProperty, prepareStart, crossCheck, Tween, // property parsing & preparation | Tween | crossCheck + truD: trueDimension, truC: trueColor, rth: rgbToHex, htr: hexToRGB, getCurrentStyle, // property parsing + }; +})); diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 0de8c9e..0000000 --- a/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 thednp - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - diff --git a/README.md b/README.md deleted file mode 100644 index a4a39c1..0000000 --- a/README.md +++ /dev/null @@ -1,139 +0,0 @@ -# KUTE.js -A minimal native Javascript tweening engine with jQuery plugin, with most essential options for web developers, designers and animators, delivering easy to use methods to set up high performance, cross-browser animations. - -Important: starting with 0.9.5 version, KUTE.js changes the prototype structure for performance, usability and browser support, as well as extensibility. The documentation and examples no longer support old versions prior to 0.9.5 release. - -# CDN -Thanks to jsdelivr, we have a CDN link here. - -# Demo -For documentation, examples and other cool tips, check the demo. - -# NPM/Bower -You can install this through NPM or bower respectively: -``` - $ npm install kute.js - # or - $ bower install kute.js -``` - -# CommonJS/AMD support -You can use this module through any of the common javascript module systems. For instance: - -```javascript -// NodeJS/CommonJS style -var kute = require("kute.js"); -// Add Bezier Easing -require("kute.js/kute-bezier"); -// Add Physics Easing -require("kute.js/kute-physics"); - -// AMD -define([ - "kute.js", - "kute.js/kute-jquery.js", // optional for jQuery apps - "kute.js/kute-bezier.js", // optional for more accurate easing functions - "kute.js/kute-physics.js" // optional for more flexible & accurate easing functions -], function(KUTE){ - // ... -}); -``` - -# Basic Usage -At a glance, you can write one line and you're done. -```javascript -//vanilla js -KUTE.fromTo('selector', fromValues, toValues, options).start(); - -//with jQuery plugin -var tween = $('selector').KUTE('fromTo', fromValues, toValues, options); -$(tween).KUTE('start'); -``` - -# Advanced Usage -Quite easily, you can write 'bit more lines and you're making the earth go round. -```javascript -//vanilla js is always the coolest -KUTE.fromTo(el, - { translate: 0, opacity: 1 }, // fromValues - { translate: 150, opacity: 0 }, // toValues - - // tween options object - { duration: 500, delay: 0, easing : 'exponentialInOut', // basic options - - // callbacks - start: functionOne, // run function when tween starts - complete: functionTwo, // run function when tween animation is finished - update: functionThree // run function while tween running - stop: functionThree // run function when tween stopped - pause: functionThree // run function when tween paused - resume: functionThree // run function when resuming tween - } -).start(); // this is to start animation right away -``` - -# jQuery Plugin -This aims to make the KUTE.js script work native within other jQuery apps but it's not always really needed as we will see in the second subchapter here. The plugin is just a few bits of code to bridge all of the the awesome `kute.js` methods to your jQuery apps. The plugin can be found in the [/master](https://github.com/thednp/kute.js/blob/master/kute-jquery.js) folder. So let's have a look at the syntax. - -## Using the jQuery Plugin -Here's a KUTE.js jQuery Plugin example that showcases most common usage in future apps: -```javascript -// first we define the object(s) -var tween = $('selector').KUTE('fromTo', // apply fromTo() method to selector - - { translate: 0, opacity: 1 }, // fromValues - { translate: 150, opacity: 0 }, // toValues - - // tween options object - { duration: 500, delay: 0, easing : 'exponentialInOut', // basic options - - //callbacks - start: functionOne, // run function when tween starts - complete: functionTwo, // run function when tween animation is finished - update: functionThree // run function while tween running - stop: functionThree // run function when tween stopped - pause: functionThree // run function when tween paused - resume: functionThree // run function when resuming tween - } -); - -// then we apply the tween control methods, like start -$(tween).KUTE('start'); -``` - -## Alternative usage in jQuery powered applications -In some cases you can handle animations inside jQuery applications even without the plugin. Here's how the code could look like: -```javascript -var tween = KUTE.fromTo($('selector')[0], fromValues, toValues, options); -tween.start(); -``` -Pay attention to that `$('selector')[0]` as jQuery always creates an array of selected objects and not a single object, that is why we need to focus a tween object to a single HTML object and not a selection of objects. Selections of objects should be handled with `for() {}` loops if that is the case, while the jQuery Plugin handles this properly for your app, as you would expect it to. - - -# How it works -* it computes all the values before starting the animation, then caches them to avoid layout thrashing that occur during animation -* handles all kinds of `transform` properties and makes sure to always use the same order of the `transform` properties (`translate`, `rotate`, `skew`, `scale`) -* allows you to set `perspective` for an element or it's parent for 3D transforms -* computes properties' values properly according to their measurement unit (px,%,deg,etc) -* properly handles cross browser 3D `transform` with `perspective` and `perspective-origin` for element or it's parent -* converts `HEX` colors to `RGB` and tweens the numeric values, then ALWAYS updates color via `RGB` -* properly replaces `top`, `centered` or any other background position with proper value to be able to tween -* for most supported properties it reads the current element computed style property value as initial value (via `currentStyle || getComputedStyle`) -* because it can read properties values from previous tween animations, KUTE.js can do some awesome chaining with it's `.to()` method -* allows you to add many callbacks: `start`, `update`, `complete`, `pause`, `stop`, and they can be set as tween options -* since `translate3D` is best for movement animation performance, `kute.js` will always use it -* accepts "nice & easy string" easing functions, like `linear` or `easingExponentialOut` (removes the use of the evil `eval`, making development safer, easier and closer to standards :) -* uses all 31 Robert Penner's easing functions, as well as bezier and physics easing functions -* handles browser prefixes for you for `transform`, `perspective`, `perspective-origin`, `border-radius` and `requestAnimationFrame` -* all this is possible with a core script of less than 20k size! - -# Browser Support -Since most modern browsers can handle pretty much everything, legacy browsers need some help, so give them polyfills. I also packed a small polyfill set with most essential features required by KUTE.js to work, it's called [minifill](https://github.com/thednp/minifill), try it. - -# Contributions -* Dav aka [@dalisoft](https://github.com/dalisoft) contributed a great deal for the performance and functionality of KUTE.js -* [Ingwie Phoenix](https://github.com/IngwiePhoenix): RequireJS/CommonJS compatibility and usability with common package managers -* Others who [contribute](https://github.com/thednp/kute.js/graphs/contributors) to the project - -# License -MIT License diff --git a/bower.json b/bower.json deleted file mode 100644 index 1c8ae59..0000000 --- a/bower.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "KUTE.js", - "version": "1.0.1", - "homepage": "http://thednp.github.io/kute.js", - "authors": [ - "thednp" - ], - "description": "A minimal Native Javascript animation engine with jQuery plugin.", - "main": "kute.js", - "moduleType": [ - "amd", - "globals", - "node" - ], - "keywords": [ - "animations", - "animation engine", - "native-javascript", - "kute.js", - "tweening", - "engine" - ], - "license": "MIT", - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "test", - "tests" - ], - "dependencies": {} -} diff --git a/coffeeScript.js b/coffeeScript.js new file mode 100644 index 0000000..ff4da49 --- /dev/null +++ b/coffeeScript.js @@ -0,0 +1,1063 @@ +### KUTE.js - The Light Tweening Engine +# by dnp_theme +# Licensed under MIT-License +### + +((root, factory) -> + if typeof define == 'function' and define.amd + define [], factory + # AMD. Register as an anonymous module. + else if typeof exports == 'object' + module.exports = factory() + # Node, not strict CommonJS + else + root.KUTE = factory() + return +) this, -> + 'use strict' + # set a custom scope for KUTE.js + g = if typeof global != 'undefined' then global else window + time = g.performance + tweens = [] + tick = null + # tick must be null!! + #supported properties + _colors = [ + 'color' + 'backgroundColor' + ] + _boxModel = [ + 'top' + 'left' + 'width' + 'height' + ] + _transform = [ + 'translate3d' + 'translateX' + 'translateY' + 'translateZ' + 'rotate' + 'translate' + 'rotateX' + 'rotateY' + 'rotateZ' + 'skewX' + 'skewY' + 'scale' + ] + _scroll = [ 'scroll' ] + _opacity = [ 'opacity' ] + _all = _colors.concat(_opacity, _boxModel, _transform) + al = _all.length + _defaults = {} + #all properties default values + #populate default values object + i = 0 + while i < al + p = _all[i] + if _colors.indexOf(p) != -1 + _defaults[p] = 'rgba(0,0,0,0)' + # _defaults[p] = {r:0,g:0,b:0,a:1}; // no unit/suffix + else if _boxModel.indexOf(p) != -1 + _defaults[p] = 0 + else if p == 'translate3d' + # px + _defaults[p] = [ + 0 + 0 + 0 + ] + else if p == 'translate' + # px + _defaults[p] = [ + 0 + 0 + ] + else if p == 'rotate' or /X|Y|Z/.test(p) + # deg + _defaults[p] = 0 + else if p == 'scale' or p == 'opacity' + # unitless + _defaults[p] = 1 + p = null + i++ + # default tween options, since 1.6.1 + defaultOptions = + duration: 700 + delay: 0 + offset: 0 + repeat: 0 + repeatDelay: 0 + yoyo: false + easing: 'linear' + keepHex: false + + getPrefix = -> + `var i` + `var i` + #returns browser prefix + div = document.createElement('div') + i = 0 + pf = [ + 'Moz' + 'moz' + 'Webkit' + 'webkit' + 'O' + 'o' + 'Ms' + 'ms' + ] + s = [ + 'MozTransform' + 'mozTransform' + 'WebkitTransform' + 'webkitTransform' + 'OTransform' + 'oTransform' + 'MsTransform' + 'msTransform' + ] + i = 0 + pl = pf.length + while i < pl + if s[i] of div.style + return pf[i] + i++ + div = null + return + + property = (p) -> + # returns prefixed property | property + r = if !(p of document.body.style) then true else false + f = getPrefix() + # is prefix required for property | prefix + if r then f + p.charAt(0).toUpperCase() + p.slice(1) else p + + selector = (el, multi) -> + # a public selector utility + nl = undefined + if multi + nl = if el instanceof Object or typeof el == 'object' then el else document.querySelectorAll(el) + else + nl = if typeof el == 'object' then el else if /^#/.test(el) then document.getElementById(el.replace('#', '')) else document.querySelector(el) + if nl == null and el != 'window' + throw new TypeError('Element not found or incorrect selector: ' + el) + nl + + radToDeg = (a) -> + a * 180 / Math.PI + + trueDimension = (d, p) -> + `var i` + #true dimension returns { v = value, u = unit } + x = parseInt(d) or 0 + mu = [ + 'px' + '%' + 'deg' + 'rad' + 'em' + 'rem' + 'vh' + 'vw' + ] + y = undefined + i = 0 + l = mu.length + while i < l + if typeof d == 'string' and d.indexOf(mu[i]) != -1 + y = mu[i] + break + i++ + y = if y != undefined then y else if p then 'deg' else 'px' + { + v: x + u: y + } + + trueColor = (v) -> + # replace transparent and transform any color to rgba()/rgb() + if /rgb|rgba/.test(v) + # first check if it's a rgb string + vrgb = v.replace(/\s|\)/, '').split('(')[1].split(',') + y = if vrgb[3] then vrgb[3] else null + if !y + return { + r: parseInt(vrgb[0]) + g: parseInt(vrgb[1]) + b: parseInt(vrgb[2]) + } + else + return { + r: parseInt(vrgb[0]) + g: parseInt(vrgb[1]) + b: parseInt(vrgb[2]) + a: parseFloat(y) + } + else if /^#/.test(v) + fromHex = hexToRGB(v) + return { + r: fromHex.r + g: fromHex.g + b: fromHex.b + } + else if /transparent|none|initial|inherit/.test(v) + return { + r: 0 + g: 0 + b: 0 + a: 0 + } + else if !/^#|^rgb/.test(v) + # maybe we can check for web safe colors + h = document.getElementsByTagName('head')[0] + h.style.color = v + webColor = g.getComputedStyle(h, null).color + webColor = if /rgb/.test(webColor) then webColor.replace(/[^\d,]/g, '').split(',') else [ + 0 + 0 + 0 + ] + h.style.color = '' + return { + r: parseInt(webColor[0]) + g: parseInt(webColor[1]) + b: parseInt(webColor[2]) + } + return + rgbToHex = (r, g, b) -> + # transform rgb to hex or vice-versa | webkit browsers ignore HEX, always use RGB/RGBA + '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1) + hexToRGB = (hex) -> + shr = /^#?([a-f\d])([a-f\d])([a-f\d])$/i + # Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") + hex = hex.replace(shr, (m, r, g, b) -> + r + r + g + g + b + b + ) + result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex) + if result then + r: parseInt(result[1], 16) + g: parseInt(result[2], 16) + b: parseInt(result[3], 16) else null + getInlineStyle = (el, p) -> + `var i` + # get transform style for element from cssText for .to() method, the sp is for transform property + if !el + return + # if the scroll applies to `window` it returns as it has no styling + css = el.style.cssText.replace(/\s/g, '').split(';') + trsf = {} + #the transform object + # if we have any inline style in the cssText attribute, usually it has higher priority + i = 0 + csl = css.length + while i < csl + if /transform/i.test(css[i]) + tps = css[i].split(':')[1].split(')') + #all transform properties + k = 0 + tpl = tps.length - 1 + while k < tpl + tpv = tps[k].split('(') + tp = tpv[0] + tv = tpv[1] + #each transform property + if _transform.indexOf(tp) != -1 + trsf[tp] = if /translate3d/.test(tp) then tv.split(',') else tv + k++ + i++ + trsf + getCurrentStyle = (el, p) -> + # get computed style property for element for .to() method + styleAttribute = el.style + computedStyle = g.getComputedStyle(el, null) or el.currentStyle + pp = property(p) + styleValue = if styleAttribute[p] and !/auto|initial|none|unset/.test(styleAttribute[p]) then styleAttribute[p] else computedStyle[pp] + # s the property style value + if p != 'transform' and (pp of computedStyle or pp of styleAttribute) + if styleValue + if pp == 'filter' + # handle IE8 opacity + filterValue = parseInt(styleValue.split('=')[1].replace(')', '')) + return parseFloat(filterValue / 100) + else + return styleValue + else + return _defaults[p] + return + getAll = -> + tweens + removeAll = -> + tweens = [] + return + add = (tw) -> + tweens.push tw + return + remove = (tw) -> + `var i` + i = tweens.indexOf(tw) + if i != -1 + tweens.splice i, 1 + return + stop = -> + if tick + _cancelAnimationFrame tick + tick = null + return + canTouch = 'ontouchstart' of g or navigator and navigator.msMaxTouchPoints or false + touchOrWheel = if canTouch then 'touchstart' else 'mousewheel' + mouseEnter = 'mouseenter' + _requestAnimationFrame = g.requestAnimationFrame or g.webkitRequestAnimationFrame or (c) -> + setTimeout c, 16 + _cancelAnimationFrame = g.cancelAnimationFrame or g.webkitCancelRequestAnimationFrame or (c) -> + clearTimeout c + transformProperty = property('transform') + body = document.body + html = document.getElementsByTagName('HTML')[0] + scrollContainer = if navigator and /webkit/i.test(navigator.userAgent) or document.compatMode == 'BackCompat' then body else html + isIE = if navigator and new RegExp('MSIE ([0-9]{1,}[.0-9]{0,})').exec(navigator.userAgent) != null then parseFloat(RegExp.$1) else false + isIE8 = isIE == 8 + isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) + # we optimize morph depending on device type + # KUTE.js INTERPOLATORS + interpolate = g.Interpolate = {} + number = + interpolate.number = (a, b, v) -> + # number1, number2, progress + a = +a + b -= a + a + b * v + unit = + interpolate.unit = (a, b, u, v) -> + # number1, number2, unit, progress + a = +a + b -= a + a + b * v + u + color = + interpolate.color = (a, b, v, h) -> + # rgba1, rgba2, progress, convertToHex(true/false) + _c = {} + c = undefined + n = number + ep = ')' + cm = ',' + r = 'rgb(' + ra = 'rgba(' + for c of b + `c = c` + _c[c] = if c != 'a' then number(a[c], b[c], v) >> 0 or 0 else if a[c] and b[c] then (number(a[c], b[c], v) * 100 >> 0) / 100 else null + if h then rgbToHex(_c.r, _c.g, _c.b) else if !_c.a then r + _c.r + cm + _c.g + cm + _c.b + ep else ra + _c.r + cm + _c.g + cm + _c.b + cm + _c.a + ep + translate = interpolate.translate = if isMobile then ((a, b, u, v) -> + translation = {} + for ax of b + translation[ax] = (if a[ax] == b[ax] then b[ax] else a[ax] + (b[ax] - (a[ax])) * v >> 0) + u + if translation.x or translation.y then 'translate(' + translation.x + ',' + translation.y + ')' else 'translate3d(' + translation.translateX + ',' + translation.translateY + ',' + translation.translateZ + ')' + ) else ((a, b, u, v) -> + translation = {} + for ax of b + translation[ax] = (if a[ax] == b[ax] then b[ax] else ((a[ax] + (b[ax] - (a[ax])) * v) * 100 >> 0) / 100) + u + if translation.x or translation.y then 'translate(' + translation.x + ',' + translation.y + ')' else 'translate3d(' + translation.translateX + ',' + translation.translateY + ',' + translation.translateZ + ')' + ) + rotate = + interpolate.rotate = (a, b, u, v) -> + rotation = {} + for rx of b + rotation[rx] = if rx == 'z' then 'rotate(' + ((a[rx] + (b[rx] - (a[rx])) * v) * 100 >> 0) / 100 + u + ')' else rx + '(' + ((a[rx] + (b[rx] - (a[rx])) * v) * 100 >> 0) / 100 + u + ')' + if rotation.z then rotation.z else (rotation.rotateX or '') + (rotation.rotateY or '') + (rotation.rotateZ or '') + skew = + interpolate.skew = (a, b, u, v) -> + skewProp = {} + for sx of b + skewProp[sx] = sx + '(' + ((a[sx] + (b[sx] - (a[sx])) * v) * 10 >> 0) / 10 + u + ')' + (skewProp.skewX or '') + (skewProp.skewY or '') + scale = + interpolate.scale = (a, b, v) -> + 'scale(' + ((a + (b - a) * v) * 1000 >> 0) / 1000 + ')' + DOM = {} + ticker = (t) -> + `var i` + i = 0 + while i < tweens.length + if update.call(tweens[i], t) + i++ + else + tweens.splice i, 1 + tick = _requestAnimationFrame(ticker) + return + update = (t) -> + `var p` + `var i` + t = t or time.now() + if t < @_startTime and @playing + return true + elapsed = Math.min((t - (@_startTime)) / @options.duration, 1) + progress = @options.easing(elapsed) + # calculate progress + for p of @valuesEnd + DOM[p] @element, p, @valuesStart[p], @valuesEnd[p], progress, @options + #render the CSS update + if @options.update + @options.update.call() + # fire the updateCallback + if elapsed == 1 + if @options.repeat > 0 + if isFinite(@options.repeat) + @options.repeat-- + if @options.yoyo + # handle yoyo + @reversed = !@reversed + reverse.call this + @_startTime = if @options.yoyo and !@reversed then t + @options.repeatDelay else t + #set the right time for delay + return true + else + if @options.complete + @options.complete.call() + scrollOut.call this + # unbind preventing scroll when scroll tween finished + i = 0 + ctl = @options.chain.length + while i < ctl + # start animating chained tweens + @options.chain[i].start() + i++ + #stop ticking when finished + close.call this + return false + true + perspective = -> + el = @element + ops = @options + if ops.perspective != undefined and transformProperty of @valuesEnd + # element perspective + @valuesStart[transformProperty]['perspective'] = @valuesEnd[transformProperty]['perspective'] + # element transform origin / we filter it out for svgTransform to fix the Firefox transformOrigin bug https://bugzilla.mozilla.org/show_bug.cgi?id=923193 + if ops.transformOrigin != undefined and !('svgTransform' of @valuesEnd) + el.style[property('transformOrigin')] = ops.transformOrigin + # set transformOrigin for CSS3 transforms only + if ops.perspectiveOrigin != undefined + el.style[property('perspectiveOrigin')] = ops.perspectiveOrigin + # element perspective origin + if ops.parentPerspective != undefined + el.parentNode.style[property('perspective')] = ops.parentPerspective + 'px' + # parent perspective + if ops.parentPerspectiveOrigin != undefined + el.parentNode.style[property('perspectiveOrigin')] = ops.parentPerspectiveOrigin + # parent perspective origin + return + prepareStart = {} + crossCheck = {} + parseProperty = + boxModel: (p, v) -> + if !(p of DOM) + DOM[p] = (l, p, a, b, v) -> + l.style[p] = (if v > 0.99 or v < 0.01 then (number(a, b, v) * 10 >> 0) / 10 else number(a, b, v) >> 0) + 'px' + return + boxValue = trueDimension(v) + if boxValue.u == '%' then boxValue.v * @element.offsetWidth / 100 else boxValue.v + transform: (p, v) -> + if !(transformProperty of DOM) + DOM[transformProperty] = (l, p, a, b, v, o) -> + l.style[p] = (a.perspective or '') + (if 'translate' of a then translate(a.translate, b.translate, 'px', v) else '') + (if 'rotate' of a then rotate(a.rotate, b.rotate, 'deg', v) else '') + (if 'skew' of a then skew(a.skew, b.skew, 'deg', v) else '') + (if 'scale' of a then scale(a.scale, b.scale, v) else '') + return + # process each transform property + if /translate/.test(p) + if p == 'translate3d' + t3d = v.split(',') + t3d0 = trueDimension(t3d[0]) + t3d1 = trueDimension(t3d[1], t3d2 = trueDimension(t3d[2])) + return { + translateX: if t3d0.u == '%' then t3d0.v * @element.offsetWidth / 100 else t3d0.v + translateY: if t3d1.u == '%' then t3d1.v * @element.offsetHeight / 100 else t3d1.v + translateZ: if t3d2.u == '%' then t3d2.v * (@element.offsetHeight + @element.offsetWidth) / 200 else t3d2.v + } + else if /^translate(?:[XYZ])$/.test(p) + t1d = trueDimension(v) + percentOffset = if /X/.test(p) then @element.offsetWidth / 100 else if /Y/.test(p) then @element.offsetHeight / 100 else (@element.offsetWidth + @element.offsetHeight) / 200 + return if t1d.u == '%' then t1d.v * percentOffset else t1d.v + else if p == 'translate' + tv = if typeof v == 'string' then v.split(',') else v + t2d = {} + t2dv = undefined + t2d0 = trueDimension(tv[0]) + t2d1 = if tv.length then trueDimension(tv[1]) else + v: 0 + u: 'px' + if tv instanceof Array + t2d.x = if t2d0.u == '%' then t2d0.v * @element.offsetWidth / 100 else t2d0.v + t2d.y = if t2d1.u == '%' then t2d1.v * @element.offsetHeight / 100 else t2d1.v + else + t2dv = trueDimension(tv) + t2d.x = if t2dv.u == '%' then t2dv.v * @element.offsetWidth / 100 else t2dv.v + t2d.y = 0 + return t2d + else if /rotate|skew/.test(p) + if /^rotate(?:[XYZ])$|skew(?:[XY])$/.test(p) + r3d = trueDimension(v, true) + return if r3d.u == 'rad' then radToDeg(r3d.v) else r3d.v + else if p == 'rotate' + r2d = {} + r2dv = trueDimension(v, true) + r2d.z = if r2dv.u == 'rad' then radToDeg(r2dv.v) else r2dv.v + return r2d + else if p == 'scale' + return parseFloat(v) + # this must be parseFloat(v) + return + unitless: (p, v) -> + # scroll | opacity + if /scroll/.test(p) and !(p of DOM) + DOM[p] = (l, p, a, b, v) -> + l.scrollTop = number(a, b, v) >> 0 + return + else if p == 'opacity' + if !(p of DOM) + if isIE8 + DOM[p] = (l, p, a, b, v) -> + st = 'alpha(opacity=' + ep = ')' + l.style.filter = st + (number(a, b, v) * 100 >> 0) + ep + return + else + DOM[p] = (l, p, a, b, v) -> + l.style.opacity = (number(a, b, v) * 100 >> 0) / 100 + return + parseFloat v + colors: (p, v) -> + # colors + if !(p of DOM) + DOM[p] = (l, p, a, b, v, o) -> + l.style[p] = color(a, b, v, o.keepHex) + return + trueColor v + preparePropertiesObject = (obj, fn) -> + # this, props object, type: start/end + element = @element + propertiesObject = if fn == 'start' then @valuesStart else @valuesEnd + skewObject = {} + rotateObject = {} + translateObject = {} + transformObject = {} + for x of obj + if _transform.indexOf(x) != -1 + # transform object gets built here + if /^translate(?:[XYZ]|3d)$/.test(x) + #process translate3d + ta = [ + 'X' + 'Y' + 'Z' + ] + #coordinates // translate[x] = pp(x, obj[x]); + f = 0 + while f < 3 + a = ta[f] + if /3d/.test(x) + translateObject['translate' + a] = parseProperty.transform.call(this, 'translate' + a, obj[x][f]) + else + translateObject['translate' + a] = if 'translate' + a of obj then parseProperty.transform.call(this, 'translate' + a, obj['translate' + a]) else 0 + f++ + transformObject['translate'] = translateObject + else if /^rotate(?:[XYZ])$|^skew(?:[XY])$/.test(x) + #process rotation/skew + ap = if /rotate/.test(x) then 'rotate' else 'skew' + ra = [ + 'X' + 'Y' + 'Z' + ] + rtp = if ap == 'rotate' then rotateObject else skewObject + r = 0 + while r < 3 + v = ra[r] + if obj[ap + v] != undefined and x != 'skewZ' + rtp[ap + v] = parseProperty.transform.call(this, ap + v, obj[ap + v]) + r++ + transformObject[ap] = rtp + else if /(rotate|translate|scale)$/.test(x) + #process 2d translation / rotation + transformObject[x] = parseProperty.transform.call(this, x, obj[x]) + propertiesObject[transformProperty] = transformObject + else + if _boxModel.indexOf(x) != -1 + propertiesObject[x] = parseProperty.boxModel.call(this, x, obj[x]) + else if _opacity.indexOf(x) != -1 or x == 'scroll' + propertiesObject[x] = parseProperty.unitless.call(this, x, obj[x]) + else if _colors.indexOf(x) != -1 + propertiesObject[x] = parseProperty.colors.call(this, x, obj[x]) + else if x of parseProperty + # or any other property from css/ attr / svg / third party plugins + propertiesObject[x] = parseProperty[x].call(this, x, obj[x]) + return + reverse = -> + `var p` + if @options.yoyo + for p of @valuesEnd + tmp = @valuesRepeat[p] + @valuesRepeat[p] = @valuesEnd[p] + @valuesEnd[p] = tmp + @valuesStart[p] = @valuesRepeat[p] + return + close = -> + # when animation is finished reset repeat, yoyo&reversed tweens + if @repeat > 0 + @options.repeat = @repeat + if @options.yoyo and @reversed == true + reverse.call this + @reversed = false + @playing = false + setTimeout (-> + if !tweens.length + stop() + return + ), 48 + # when all animations are finished, stop ticking after ~3 frames + return + preventScroll = (e) -> + # prevent mousewheel or touch events while tweening scroll + data = document.body.getAttribute('data-tweening') + if data and data == 'scroll' + e.preventDefault() + return + scrollOut = -> + #prevent scroll when tweening scroll + if 'scroll' of @valuesEnd and document.body.getAttribute('data-tweening') + document.removeEventListener touchOrWheel, preventScroll, false + document.removeEventListener mouseEnter, preventScroll, false + document.body.removeAttribute 'data-tweening' + return + scrollIn = -> + if 'scroll' of @valuesEnd and !document.body.getAttribute('data-tweening') + document.addEventListener touchOrWheel, preventScroll, false + document.addEventListener mouseEnter, preventScroll, false + document.body.setAttribute 'data-tweening', 'scroll' + return + processEasing = (fn) -> + #process easing function + if typeof fn == 'function' + return fn + else if typeof fn == 'string' + return easing[fn] + # regular Robert Penner Easing Functions + return + + getStartValues = -> + `var p` + `var p` + # stack transform props for .to() chains + startValues = {} + currentStyle = getInlineStyle(@element, 'transform') + deg = [ + 'rotate' + 'skew' + ] + ax = [ + 'X' + 'Y' + 'Z' + ] + for p of @valuesStart + if _transform.indexOf(p) != -1 + r2d = /(rotate|translate|scale)$/.test(p) + if /translate/.test(p) and p != 'translate' + startValues['translate3d'] = currentStyle['translate3d'] or _defaults[p] + else if r2d + # 2d transforms + startValues[p] = currentStyle[p] or _defaults[p] + else if !r2d and /rotate|skew/.test(p) + # all angles + d = 0 + while d < 2 + a = 0 + while a < 3 + s = deg[d] + ax[a] + if _transform.indexOf(s) != -1 and s of @valuesStart + startValues[s] = currentStyle[s] or _defaults[s] + a++ + d++ + else + if p != 'scroll' + if p == 'opacity' and isIE8 + # handle IE8 opacity + currentOpacity = getCurrentStyle(@element, 'filter') + startValues['opacity'] = if typeof currentOpacity == 'number' then currentOpacity else _defaults['opacity'] + else + if _all.indexOf(p) != -1 + startValues[p] = getCurrentStyle(@element, p) or d[p] + else + # plugins register here + startValues[p] = if p of prepareStart then prepareStart[p].call(this, p, @valuesStart[p]) else 0 + else + startValues[p] = if @element == scrollContainer then g.pageYOffset or scrollContainer.scrollTop else @element.scrollTop + for p of currentStyle + # also add to startValues values from previous tweens + if _transform.indexOf(p) != -1 and !(p of @valuesStart) + startValues[p] = currentStyle[p] or _defaults[p] + @valuesStart = {} + preparePropertiesObject.call this, startValues, 'start' + if transformProperty of @valuesEnd + # let's stack transform + for sp of @valuesStart[transformProperty] + # sp is the object corresponding to the transform function objects translate / rotate / skew / scale + if sp != 'perspective' + if typeof @valuesStart[transformProperty][sp] == 'object' + for spp of @valuesStart[transformProperty][sp] + # 3rd level + if typeof @valuesEnd[transformProperty][sp] == 'undefined' + @valuesEnd[transformProperty][sp] = {} + if typeof @valuesStart[transformProperty][sp][spp] == 'number' and typeof @valuesEnd[transformProperty][sp][spp] == 'undefined' + @valuesEnd[transformProperty][sp][spp] = @valuesStart[transformProperty][sp][spp] + else if typeof @valuesStart[transformProperty][sp] == 'number' + if typeof @valuesEnd[transformProperty][sp] == 'undefined' + # scale + @valuesEnd[transformProperty][sp] = @valuesStart[transformProperty][sp] + return + # core easing functions + easing = g.Easing = {} + easing.linear = (t) -> + t + easing.easingSinusoidalIn = (t) -> + -Math.cos(t * Math.PI / 2) + 1 + easing.easingSinusoidalOut = (t) -> + Math.sin t * Math.PI / 2 + easing.easingSinusoidalInOut = (t) -> + -0.5 * (Math.cos(Math.PI * t) - 1) + easing.easingQuadraticIn = (t) -> + t * t + easing.easingQuadraticOut = (t) -> + t * (2 - t) + easing.easingQuadraticInOut = (t) -> + if t < .5 then 2 * t * t else -1 + (4 - (2 * t)) * t + easing.easingCubicIn = (t) -> + t * t * t + easing.easingCubicOut = (t) -> + --t * t * t + 1 + easing.easingCubicInOut = (t) -> + if t < .5 then 4 * t * t * t else (t - 1) * (2 * t - 2) * (2 * t - 2) + 1 + easing.easingQuarticIn = (t) -> + t * t * t * t + easing.easingQuarticOut = (t) -> + 1 - (--t * t * t * t) + easing.easingQuarticInOut = (t) -> + if t < .5 then 8 * t * t * t * t else 1 - (8 * --t * t * t * t) + easing.easingQuinticIn = (t) -> + t * t * t * t * t + easing.easingQuinticOut = (t) -> + 1 + --t * t * t * t * t + easing.easingQuinticInOut = (t) -> + if t < .5 then 16 * t * t * t * t * t else 1 + 16 * --t * t * t * t * t + easing.easingCircularIn = (t) -> + -(Math.sqrt(1 - (t * t)) - 1) + easing.easingCircularOut = (t) -> + Math.sqrt 1 - ((t = t - 1) * t) + easing.easingCircularInOut = (t) -> + if (t *= 2) < 1 then -0.5 * (Math.sqrt(1 - (t * t)) - 1) else 0.5 * (Math.sqrt(1 - ((t -= 2) * t)) + 1) + easing.easingExponentialIn = (t) -> + 2 ** (10 * (t - 1)) - 0.001 + easing.easingExponentialOut = (t) -> + 1 - 2 ** (-10 * t) + easing.easingExponentialInOut = (t) -> + if (t *= 2) < 1 then 0.5 * 2 ** (10 * (t - 1)) else 0.5 * (2 - 2 ** (-10 * (t - 1))) + easing.easingBackIn = (t) -> + s = 1.70158 + t * t * ((s + 1) * t - s) + easing.easingBackOut = (t) -> + s = 1.70158 + --t * t * ((s + 1) * t + s) + 1 + easing.easingBackInOut = (t) -> + s = 1.70158 * 1.525 + if (t *= 2) < 1 + return 0.5 * t * t * ((s + 1) * t - s) + 0.5 * ((t -= 2) * t * ((s + 1) * t + s) + 2) + easing.easingElasticIn = (t) -> + s = undefined + _kea = 0.1 + _kep = 0.4 + if t == 0 + return 0 + if t == 1 + return 1 + if !_kea or _kea < 1 + _kea = 1 + s = _kep / 4 + else + s = _kep * Math.asin(1 / _kea) / Math.PI * 2 + -(_kea * 2 ** (10 * (t -= 1)) * Math.sin((t - s) * Math.PI * 2 / _kep)) + easing.easingElasticOut = (t) -> + s = undefined + _kea = 0.1 + _kep = 0.4 + if t == 0 + return 0 + if t == 1 + return 1 + if !_kea or _kea < 1 + _kea = 1 + s = _kep / 4 + else + s = _kep * Math.asin(1 / _kea) / Math.PI * 2 + _kea * 2 ** (-10 * t) * Math.sin((t - s) * Math.PI * 2 / _kep) + 1 + easing.easingElasticInOut = (t) -> + s = undefined + _kea = 0.1 + _kep = 0.4 + if t == 0 + return 0 + if t == 1 + return 1 + if !_kea or _kea < 1 + _kea = 1 + s = _kep / 4 + else + s = _kep * Math.asin(1 / _kea) / Math.PI * 2 + if (t *= 2) < 1 + return -0.5 * _kea * 2 ** (10 * (t -= 1)) * Math.sin((t - s) * Math.PI * 2 / _kep) + _kea * 2 ** (-10 * (t -= 1)) * Math.sin((t - s) * Math.PI * 2 / _kep) * 0.5 + 1 + easing.easingBounceIn = (t) -> + 1 - easing.easingBounceOut(1 - t) + easing.easingBounceOut = (t) -> + if t < 1 / 2.75 + 7.5625 * t * t + else if t < 2 / 2.75 + 7.5625 * (t -= 1.5 / 2.75) * t + 0.75 + else if t < 2.5 / 2.75 + 7.5625 * (t -= 2.25 / 2.75) * t + 0.9375 + else + 7.5625 * (t -= 2.625 / 2.75) * t + 0.984375 + easing.easingBounceInOut = (t) -> + if t < 0.5 + return easing.easingBounceIn(t * 2) * 0.5 + easing.easingBounceOut(t * 2 - 1) * 0.5 + 0.5 + # single Tween object construct + Tween = (targetElement, startObject, endObject, options) -> + @element = if 'scroll' of endObject and (targetElement == undefined or targetElement == null) then scrollContainer else targetElement + # element animation is applied to + @playing = false + @reversed = false + @paused = false + @_startTime = null + @_pauseTime = null + @_startFired = false + @options = {} + for o of options + @options[o] = options[o] + @options.rpr = options.rpr or false + # internal option to process inline/computed style at start instead of init true/false + @valuesRepeat = {} + # internal valuesRepeat + @valuesEnd = {} + # valuesEnd + @valuesStart = {} + # valuesStart + preparePropertiesObject.call this, endObject, 'end' + # valuesEnd + if @options.rpr + @valuesStart = startObject + else + preparePropertiesObject.call this, startObject, 'start' + # valuesStart + if @options.perspective != undefined and transformProperty of @valuesEnd + # element transform perspective + perspectiveString = 'perspective(' + parseInt(@options.perspective) + 'px)' + @valuesEnd[transformProperty].perspective = perspectiveString + for e of @valuesEnd + if e of crossCheck and !@options.rpr + crossCheck[e].call this + # this is where we do the valuesStart and valuesEnd check for fromTo() method + @options.chain = [] + # chained Tweens + @options.easing = if options.easing and typeof processEasing(options.easing) == 'function' then processEasing(options.easing) else easing[defaultOptions.easing] + # you can only set a core easing function as default + @options.repeat = options.repeat or defaultOptions.repeat + @options.repeatDelay = options.repeatDelay or defaultOptions.repeatDelay + @options.yoyo = options.yoyo or defaultOptions.yoyo + @options.duration = options.duration or defaultOptions.duration + # duration option | default + @options.delay = options.delay or defaultOptions.delay + # delay option | default + @repeat = @options.repeat + # we cache the number of repeats to be able to put it back after all cycles finish + return + + TweenProto = Tween.prototype = + start: (t) -> + # move functions that use the ticker outside the prototype to be in the same scope with it + scrollIn.call this + if @options.rpr + getStartValues.apply this + # on start we reprocess the valuesStart for TO() method + perspective.apply this + # apply the perspective and transform origin + for e of @valuesEnd + if e of crossCheck and @options.rpr + crossCheck[e].call this + # this is where we do the valuesStart and valuesEnd check for to() method + @valuesRepeat[e] = @valuesStart[e] + # now it's a good time to start + tweens.push this + @playing = true + @paused = false + @_startFired = false + @_startTime = t or time.now() + @_startTime += @options.delay + if !@_startFired + if @options.start + @options.start.call() + @_startFired = true + !tick and ticker() + this + play: -> + if @paused and @playing + @paused = false + if @options.resume + @options.resume.call() + @_startTime += time.now() - (@_pauseTime) + add this + !tick and ticker() + # restart ticking if stopped + this + resume: -> + @play() + pause: -> + if !@paused and @playing + remove this + @paused = true + @_pauseTime = time.now() + if @options.pause + @options.pause.call() + this + stop: -> + if !@paused and @playing + remove this + @playing = false + @paused = false + scrollOut.call this + if @options.stop + @options.stop.call() + @stopChainedTweens() + close.call this + this + chain: -> + @options.chain = arguments + this + stopChainedTweens: -> + `var i` + i = 0 + ctl = @options.chain.length + while i < ctl + @options.chain[i].stop() + i++ + return + + TweensTO = (els, vE, o) -> + `var i` + # .to + @tweens = [] + options = [] + i = 0 + tl = els.length + while i < tl + options[i] = o or {} + o.delay = o.delay or defaultOptions.delay + options[i].delay = if i > 0 then o.delay + (o.offset or defaultOptions.offset) else o.delay + @tweens.push to(els[i], vE, options[i]) + i++ + return + + TweensFT = (els, vS, vE, o) -> + `var i` + # .fromTo + @tweens = [] + options = [] + i = 0 + l = els.length + while i < l + options[i] = o or {} + o.delay = o.delay or defaultOptions.delay + options[i].delay = if i > 0 then o.delay + (o.offset or defaultOptions.offset) else o.delay + @tweens.push fromTo(els[i], vS, vE, options[i]) + i++ + return + + ws = TweensTO.prototype = TweensFT.prototype = + start: (t) -> + `var i` + t = t or time.now() + i = 0 + tl = @tweens.length + while i < tl + @tweens[i].start t + i++ + this + stop: -> + `var i` + i = 0 + tl = @tweens.length + while i < tl + @tweens[i].stop() + i++ + this + pause: -> + `var i` + i = 0 + tl = @tweens.length + while i < tl + @tweens[i].pause() + i++ + this + chain: -> + @tweens[@tweens.length - 1].options.chain = arguments + this + play: -> + `var i` + i = 0 + tl = @tweens.length + while i < tl + @tweens[i].play() + i++ + this + resume: -> + @play() + + to = (element, endObject, options) -> + options = options or {} + options.rpr = true + new Tween(selector(element), endObject, endObject, options) + + fromTo = (element, startObject, endObject, options) -> + options = options or {} + new Tween(selector(element), startObject, endObject, options) + + allTo = (elements, endObject, options) -> + new TweensTO(selector(elements, true), endObject, options) + + allFromTo = (elements, f, endObject, options) -> + new TweensFT(selector(elements, true), f, endObject, options) + + { + property: property + getPrefix: getPrefix + selector: selector + processEasing: processEasing + defaultOptions: defaultOptions + to: to + fromTo: fromTo + allTo: allTo + allFromTo: allFromTo + ticker: ticker + tick: tick + tweens: tweens + update: update + dom: DOM + parseProperty: parseProperty + prepareStart: prepareStart + crossCheck: crossCheck + Tween: Tween + truD: trueDimension + truC: trueColor + rth: rgbToHex + htr: hexToRGB + getCurrentStyle: getCurrentStyle + } diff --git a/demo/about.html b/demo/about.html deleted file mode 100644 index 48dfe3c..0000000 --- a/demo/about.html +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - - - - - - - - - - - - About KUTE.js | Javascript Animation Engine - - - - - - - - - - - - - -
- -
- - - -
- -

Did you know?

-

Tween is a term used by animators and software engineers to define the numeric start, end and the inbetween values used in digital animation, while the digital animation uses these tween values on a given frequency (interval) or scaled by hardware capability (monitors refresh rate, GPU frames per second, etc). The term was introduced to the world of web development by early Javascrpt libraries and later used in dedicated animation libraries such as GSAP, Dynamics, Velocity, Shifty, our own KUTE.js here and many others.

-

Tween Object is a Javascript Object that stores temporarily or for a given time a set of variables such as tween values, HTML elements to animate, CSS properties and other tween options to be used for animation. To improve performance on repetitive animations, this object can be cached and reused whenever needed. In Javascript animation, the term tween actually refers to the tween object.

-

polyfill is a term introduced by Remy Sharp back in 2009 as "a piece of code (or plugin) that provides the technology that you, the developer, expect the browser to provide natively". Basically a polyfill covers what legacy browsers don't support or in other cases corrects the implemented behavior that is different from the standards. More details.

-

requestAnimationFrame is a Javascript method developed to enable hardware acceleration animations for the web today. In Javascript, the window.requestAnimationFrame(callback); method is all we need to setup animations really for all the above mentioned animation engines. Some developers built a polyfil to cover the legacy browsers chaos.

-

JANK is a term used when browsers miss frames due to long script execution and/or long layout recomposition. JANK is the phenomenon reffering to severe frame drops. Luckily there are people who explain all about it, so you don't have to stay in the dark.

-

Methods are functions that create tween objects or control the animation for KUTE.js, so we will encounter mostly main methods and tween control methods. Once a main method is used, then the control methods apply in a specific order.

- - -

How Does It Work?

-

Well, first things first: it's smart built. Let's briefly explain the phases:

-
    -
  1. On first initialization KUTE.js creates some variables such as supported properties and their default values, the user's browser prefix, the true scroll container (some browsers actually scroll the body, while others prefer the HTML tag), a boolean variable that makes KUTE.js aware it's working with IE8, as well as other variables required during the main thread. This phase is very important for the performance on the next phases.
  2. -
  3. In the next phase it's going to build the tween object with the chosen method according to it's distinct functionalities. If the chosen method is .to() KUTE.js will look for the current values of the properties used or assign the default values built in the previous phase. For both methods, KUTE.js collects all the data, processes values and options (for instance easing functions need to be processed if you use a string like 'easingElasticOut', right?) and builds the tween object, with all properties' values start and values end, measurement units, tween options and callback functions.
  4. -
  5. In the third phase KUTE.js is ready to start the animation, but the animation starts only after the .start() function, if used, has finished. When animation starts, KUTE.js will start ticking on the frequency decided by requestAnimationFrame or setInterval for legacy browsers, quickly updating the style for the properties and execute the update:function callback if any. Also while animating, KUTE.js will begin listening for your tween control input such as .pause() or .stop() or any other. Also, when a certain tween control method is used, KUTE.js will execute it's specific callback, if used.
  6. -
  7. When tween animation is finished, the complete:function callback function is executed and then KUTE.js starts the animation for any chained tween, or else will stop ticking with cancelAnimationFrame to save power.
  8. -
-

Basically, this is it!

- -

A Word On Performance

-

As said before, performance varies from case to case; this chapter aims to explain what you should expect working with animation engines in these various scenarios at maximum stress, usually when your CPU cooler starts to work really hard, and how scalable performance can really be on various machines, operating systems or mobile devices.

- -

Function Nesting

-

This could be one of the most important factors that influence performance, because we neglect this fact most of the time and changing the scope of an animation engine is important to look after. A quick example would be when we create tween objects on events such as click, scroll or resize, we basically set a totally different scope for the animation and we fill the memory with large chunks of trash/jank, especially on events like resize.

-

A better way to handle this is to create the tween objects outside the event handlers and only start the animation with these handlers when certain conditions are met. EG: if (window.clientWidth > 760) { myTween.start() }. Also keep in mind that this approach will eliminate any possible syncronization issues, but creating many animations is a huge temptation and this will create lots of problems for the old browsers, so keep the function nesting to as minimal as possible as a general rule.

-

In all animation engines, GSAP is the only one that exports all it's methods and computed values to the global scope to help diminish the time to access/execute, but it will find soon that it's no longer the case because modern browsers continuously improve their Javascript engines to a point where the access speed is the same, blazing fast, no matter how deep Javascript animation scope goes.

- -

Translate and Position

-

While the code execution is the fastest for the layout modifiers or what we call box-model, say the position based properties set such as left or top, they may force the entire page layout to change and thus requires the browser to repaint all elements affected by animated repositioning and their parent elements. On the other side translate doesn't trigger a repaint but involves more complex operations such as object traversing, string concatenation or check for certain conditions to be met. All of this is because translate is part of transform CSS3 property that has to stack in a single line many more properties such as rotate, skew and scale. An article by Paul Irish explains more about differences in performance between position and translation.

- -

To put it short left executes faster but requires repaint on every frame while translateX or translate3d execute slower but require no repaint on each animation frame. The winner is left, when it comes to code execution speed, but if we also count the elements' size, the larger size the more favor the translation so the overall winner is translate. The more pixels to recompose in the layout, the more time spent on each frame, and this is why translation is better in most cases, and animated positioning is best to be used as fallback animation for legacy browsers.

- -

Translate, TranslateX and Translate3D

-

While running a 2D translate:150 animation could score similar performance as translateX:150, interestingly, translate3d:[150,0,0] is slightly faster than the other translations. Some performance tests confirm that translate3d is the prefered property for hardware acceleration. For this reason, translate3d is the winner and KUTE.js always uses it even if you only use translateX or translateY for instance.

-

Similarly, if you animate the 2D translate this always goes translate(x,y) even if you use translate:150 (only for the X axis) or translate:[150,0] (both X and Y axis), for better performance as well. And by the way, this works great on IE9 and other legacy browsers.

- -

Box Model

-

We compared position with transition above, but now we are going to talk about other issues related to resizers: width, height, margin, padding and borderWidth or any of their variations. The code execution is super fast, but when resizing the window while animations are running, the browser is also computing the resize handlers, the animation performance is very very low on all browsers, especially when you animate these resize properties. When this toxic combination occurs animating a large amount of elements to animate could crash any browser, no exception, and I think any developer should know about this.

-

The resize event triggered by these resizer properties can cause some severe issues with legacy browsers such as IE8. These good old browsers don't understand much about Javascript driven layout changes and thus skip/fail to execute any handlers attached to window resize event bubbles.

-

A workaound the resizers effect on the layout would be to use them only for absolute positioned elements, this way the layout will not need to be repainted and the recomposition is limited to the element itself. If not, and you are required to provide legacy support, you must DISABLE any resize handlers for IE8 and any other browser that runs slow or crashes. You should also consider not using any resize animation for legacy browsers especially when usability and larger reach is expected.

- -

RGB and HEX

-

When animating any color property such as (text) color or background-color, KUTE.js always uses/converts to RGB/RGBA, but there is a keepHex:true tween option that overrides that. Still some browsers such as Chrome will still show you the computed style for your color as RGB no matter what. The conversion process will decrease performance, making RGB the winner.

- -

TO and FROMTO

-

The two main methods for creating animation setups (tween objects) that are coming with KUTE.js are .to() and .fromTo(). While .to() is much more simple and convenient to use, very useful for tween chaining, it has to process the starting values on every .start() delaying the animation for a few miliseconds depending on the browser and hardware, making .fromTo() the winner. On a large amount of elements animating at the same time, these scripting based delays can produce some serious syncronization issues, so caution is advised. In that case you should use .fromTo() properly.

- -

Easing Functions

-

KUTE.js comes with 3 packs of easing functions: the popular easing functions by Robert Penner, dynamics physics easing functions by Michael Villar and bezier-easing by Gaëtan Renaudeau. I've worked very hard to optimize the last 2 as much as possible, but they will never beat Robert Penner's functions in any performance test, that's an all time winner.

-

The point here is that the more accuracy a function offers, the more power needed, and the result is less performance. For instance the cubic-bezier based functions have a 0.0000001 error margin, while the Exponential easing functions by Robert Penner are somewhat glitchy on long page scrolls or translations. Interestingly, some physics based functions perform exceedingly well, and generally the difference in performance is fairly negligible even for large amounts of elements, and have no impact on very few elements.

- -

Garbage Collection

-

The goal of the development strategy is to be able to execute the script, update layout and repaint, all under 16 miliseconds, so that the animation runs constantly at 60fps. However running some repeatable animations for a large amount of elements would really give garbage collectors a lot of work and thus some frames take more than 16 miliseconds. The more properties and/or elements, the more work.

-

While garbage collection is a great way modern browsers use to clean the memory, sometimes the garbage collector can jump in anytime, cousing drops in the order of miliseconds. Still, if it's the case, there are ways to help composing the layout faster, but we will see that in the performance testing page.

- -

OSs, Desktops and Mobiles

-

The performance tests have been performed mainly on Microsoft Windows 8.1 and Ubuntu Linux 14.04 Trusty Tahr with latest nVidia graphics drivers on both OSs, all set up for maximum performance. The browsers are obviously Firefox (both OSs), Google Chrome (both OSs), Opera (both OSs) and IE11 (Win8).

-

The results show Windows based browsers came better than Ubuntu based ones, mainly because of DirectX and better drivers that greatly improve hardware accelerated graphics, while Linux still faces some noticeable issues with vertical sync among many others, but hey it's a work in progress and it's open source!

- -

The browsers' performance goes like this (from best to poorest): Google Chrome, Opera, Internet Explorer, Firefox. Yes, Firefox is the slowest on Windows OS. I never tested anything on iOS or MAC-OS but I believe Safari performs very well with transforms. Some argue that Safari outperforms Google Chrome due to the latest Webkit upgrade.

- -

Also know that legacy browsers don't support requestAnimationFrame and pollyfills usually replace it with setInterval, a clasic Javascript method that's significantly affecting performance, because it's one of the main causes for lots of JANK.

- -

Another important aspect as far as performance goes, the power saving profiles on Windows OS drops performance for desktop computers and especally laptops. Also when a laptop is unplugged, Windows automatically changes power profile drastically decreasing performance.

- -

As for the mobiles, you must know that even if you have an octacore CPU powered phone or tablet is never going to match a desktop and not even a laptop. For a mobile device these guys recommend to keep everything under 7 miliseconds for the smooth experience that most users expect and that the animation performance of a phone is actually up to 5 times lower than a desktop or laptop. I would stress that having 2 or 3 simoultaneous animations on a phone at a certain point is just about enough.

- -

Another thing to keep in mind is that scrollling on a mobile device is actually hardware accelerated animation and thus compete for power drastically reducing performance for any other CSS or Javascript driven animations. To understand how critical performance is on a mobile device, I highly recommend checking the Google I/O 2014 presentation. Now you understand how much performance really matters.

-

Remember: do not open any Javascript animation engine performance test with your phone, you may burn your battery, espectially if it's unpluggable.

- -

KUTE.js Project

-

KUTE.js continues what was started with jQueryTween (removed) and the main goal is to improve usability, compatibility, code quality and performance. KUTE.js includes a jQuery plugin to help you easily implement it in your jQuery applications, and also packs a set of tools such as bezier and physics based easing functions, all elegantly packed for convenience and distributed via CDN.

-

It all started with a fork of the popular tween.js and ended up having a KUTE.js version 0.9.5 that's almost as good as the boss, GSAP, at least in terms of performance and browser support. TweenMax have been an outstanding source of wonderful coding practices, and a very tough competitor.

-

In the hystory of the making there were consistent contributions of Dav aka @dalisoft for features such as play & pause, as well as for performance related issues. Generally I would stress that the code is a joint work of me and Dav. Big thanks Dav, well done.

-

Also I would like to thank Ingwie Phoenix for the npm/Bower and UMD implementations.

- - -
- - - - -
- - - - - - - - diff --git a/demo/api.html b/demo/api.html deleted file mode 100644 index c66a9d2..0000000 --- a/demo/api.html +++ /dev/null @@ -1,386 +0,0 @@ - - - - - - - - - - - - - - - - - KUTE.js Developer API | Javascript Animation Engine - - - - - - - - - - - - - - - - - - - -
- -
- - - -
- -

Getting Started

-

Welcome to KUTE.js API documentation, here we're going to talk about how to download, install, use, control and set up cross browser animations, in great detailed. KUTE.js can be found on CDN and also npm and Bower repositories with all it's features and tools.

- -

Bower and NPM

-

You can install KUTE.js package by using either Bower or NPM.

-
$ npm install --save kute.js
-# Or
-$ bower install --save kute.js
-
- -

Websites

-

In your website add the following code, the best would be to put it at the end of your body tag:

-
<script src="https://cdn.jsdelivr.net/kute.js/1.0.1/kute.min.js"></script> <!-- core KUTE.js -->
- -

Also you can include the tools that you need for your project:

-
<script src="https://cdn.jsdelivr.net/kute.js/1.0.1/kute-jquery.min.js"></script> <!-- jQuery Plugin -->
-<script src="https://cdn.jsdelivr.net/kute.js/1.0.1/kute-easing.min.js"></script> <!-- Bezier Easing Functions -->
-<script src="https://cdn.jsdelivr.net/kute.js/1.0.1/kute-physics.min.js"></script> <!-- Physics Easing Functions -->
-
-

Your awesome animation coding would follow after these script links.

- -

Targeting Legacy Browsers

-

You need to know when users' browser is a legacy one in order to use KUTE.js only for what browsers actually support. A quick note here: IE8 doesn't support any transform property or RGBA colors while IE9 can only do 2D transformations. Check the 2D transforms and the 3D transforms browser support list for more information.

-

Don't use Modernizr, the best thing you can actually do is to use the Microsoft's synthax for it's own legacy browsers, and here is the full refference on that. For other legacy browsers there is a ton of ways to target them, quite efficiently I would say: there you go.

-
- -
-

Main Methods

-

These methods allow you to create tween objects and collections of tween objects; as we know, a tween object is essentially like an animation setup for a given HTML element, defining CSS properties, animation duration, repeat or other options. The methods have different uses and performance scores while making it easy to work with.

- -

Single Tween Object

-

As the heading suggests, the following two methods allow you to create tween objects for a single HTML element, except when used in combination with jQuery and the KUTE.js plugin for jQuery, where, as jQuery always does, it always works with collections of elements.

-

.to() method is the most simple method which allows you to create tween objects for animating CSS properties from a specific default value OR from current/computed value TO a desired value. - It's performance is not the same as for the .fromTo() method as it has to compute the default/current value on tween .start() and thus delays the animation for a couple of miliseconds; still this feature is great for simple animations AND it has the ability to stack transform properties as they go, making smooth transform animations on chained tweens. See the .start() method for the solution for sync/delay issue.

-

Considering a given div element is already transparent, a super quick example would be:

-
KUTE.to(div,{opacity:1}).start()
- -

.fromTo() method is the best way to build animations for BEST performance and absolute control. The tests prove this method to be the fastest method but unlike the .to() method, it does not stack transform properties on chained tweens. Along with the performance advantage, you can set measurement units for both starting and end values, to avoid glitches. We've talked about this in the features page. Here's a quick example:

-
KUTE.fromTo(div,{opacity:1},{opacity:0}).start()
- -

Tween Object Collections

-

The two new methods allow you to create animations for multiple HTML elements at the same time, all in a single line of code. They use the above methods to create a tween object for each element of the collection and also enable the tween control methods in this new context.

-

.allTo() method allows you to create an array of tween objects for a collection of elements. This method is using the above .to() method and inherits it's functionality. Considering a given collection myDivs elements, a nice example would be:

-
// on the fly, grab the elements by className, 
-// do the tween objects array, and start kicking
-KUTE.allTo( '.my-div-class', {opacity:1}, {offset: 200, duration: 500} ).start();
-
-// or we cache the objects for better performance and / or later control
-var myDivs          = document.querySelectorAll('.my-div-class');
-var myDivsTweens    = KUTE.allTo( myDivs, {opacity:1}, {offset: 200, duration: 500} );
-
- -

.allFromTo() method is also a method to animate a collection of elements and it uses the .fromTo() method. Quick example:

-
KUTE.allFromTo( myDivs, {opacity:1}, {opacity:0}, {offset: 200, duration: 500} ).start()
- -

Considering that the selector matches two DIV elements, the value for the above variable myDivsTweens is an object that only stores the two tweens, one for each element found:

-

-myDivsTweens = { // console.log(myDivsTweens);
-    tweens = [ Tween, Tween ] console.log(myDivsTweens.tweens);
-}
-
-

As you can see the above code, these methods have a specific tween option called offset that allows you to set a delay in miliseconds between the starting time of each tween animation. Most tween control methods apply to both methods, except for the .chain() method. In order to chain another tween to one of the myDivsTweens objects, we would need to access it from the array, but let's leave that for later.

-
- -
-

Tween Control Methods

-

These methods allows you to control when the animation starts or stops. Let's write a basic tween object to work with the methods:

-
var tween = KUTE.fromTo(div,{opacity:1},{opacity:0});
-

This tween object is now ready to work with the methods.

- -

Starting Animations

-

.start() method starts animation for a given tween object. It can start the animation for both cached and non-cached objects. Unlike previous versions of KUTE.js, where animation started immediately after tween object creation, now you have to manually start them. This method also applies to arrays of tween objects created with .allTo() and .allFromTo() methods.

-
//cached object defined above
-tween.start();
-
-// non-cached object are created on the fly and garbage collected after animation has finised
-KUTE.fromTo(div,{opacity:1},{opacity:0}).start();
-
-// also start the tween at a certain time
-tween.start(now); // where now must be the current or future time as number, see below
-
-// lastly the method works with tweens made with .allTo() and .allFromTo() methods
-KUTE.allFromTo(divs,{opacity:1},{opacity:0}).start();
-KUTE.allTo(divs,{opacity:0}).start();
-
- -

As you can see, you can also set a time for the animation to start, example: tween.start(myTimeValue). Having access to the method is useful when starting animation for large amounts of elements with same properties at the same time because using it properly eliminates any syncronization issue that may occur on animations start, even if you are using the .to() method. The trick is super duper simple:

- -
// step 1 - create an empty array and grab the elements to animate
-var tweens = [], myElements = document.querySelector('.myManyElements'), numberOfElements = myElements.length;
-
-// step 2 - define tween objects for each element
-for (var i = 0; i < numberOfElements; i++) {
-	var tween = KUTE.fromTo(myElements[i], fromValues, toValues, options);
-	//now we populate the tweens array
-	tweens.push(tween);
-}
-
-// step 3 - calculate the right time to start
-// first we need the exact current time
-var now = window.performance.now(); // this returns the exact current time in numeric format
-
-// also we estimate/calculate an adjustment lag 
-// depending on the number of the elements AND hardware capability
-// maybe (numberOfElements / 16) would be an accurate value for PCs
-var lag = 100; // number of miliseconds for the script to built tween objects for all elements
-
-// step4 - we just start the animation for all elements at once
-for (var i = 0; i < numberOfElements; i++) {
-	tweens[i].start(now+lag);
-}
-
- -

In other cases the new methods .allTo() and .allFromTo() can be more useful.

- -

Stopping Animation

-

.stop() method stops animation for a given tween object or an array of tween objects (built with .to()/.fromTo() methods) while animating. You cannot stop the animation for tween objects created on the fly, only for cached objects. Let's assume that for the given tween we decide to stop the animation via click action:

-
// for a tween object
-stopButton.addEventListener('click', function(){
-	myTween.stop(); // myMultiTweens.stop();
-}, false);
-
- -

Pausing Animation

-

.pause() method freezez the animation at any given time for a given tween object or collection, and unlike the .stop() method, this one allows resuming the animation on a later use of the next method .play().

-
pauseButton.addEventListener('click', function(){
-	tween.pause(); // or myMultiTweens.pause();
-}, false);
-
- -

Resuming Paused Animation

-

.play() or .resume() methods allows you to resume an animation for a given tween object or collection of tweens, only if it was paused or else will produce no effect.

-
playButton.addEventListener('click', function(){
-	tween.play(); // or tween.resume(); || or myMultiTweens.resume();
-}, false);
-
- -

Chaining Tweens

-

.chain() method can be used to chain tweens together. When the animation finishes for a given tween, it triggers the animation start for another tween.

-
var tween2 = KUTE.fromTo(div,{left:50},{left:0});
-
-//the first tween chains the new tween
-tween.chain(tween2);
-
-//the new tween chains the first one creating a loop
-tween2.chain(tween);
-
- -

It's also possible to chain multiple tweens, just as shown in the below example.

-
//chain multiple tweens
-tween.chain(tween1,tween2);
-
- -

Another thing we talked before is the ability to chain to one of the tween object within the array built with .allTo() or .allFromTo() methods.

-
// chain to a tween from collection
-var tweensCollection = KUTE.allTo('.a-class-for-multiple-elements', {opacity: 1}, {opacity: 0}, {duration: 500});
-
-// considering the collection has 5 tweens,
-// the array is right here tweensCollection.tweens, so
-// let's grab the second and chain another tween to it
-tweensCollection.tweens[1].chain(tween2);
-
- - -
- -
-

Tween Options

-

Common Options

-

These options affect all types of tweens, no matter the properties used or context.

-

duration: 500 option allows you to set the animation duration in miliseconds. The default value is 700.

-

repeat: 20 option allows you to run the animation of given tween multiple times. The default value is 0.

-

delay: 500 option allows you to delay the tween animation for a certain number of miliseconds. The default value is 0.

-

offset: 200 option is only for .allTo() and .allFromTo() methods. This allows you to set a base delay in miliseconds that increases with each element in the collection. This has no effect on other methods and the default value is 0.

-

repeatDelay: 500 option allows you to set a number of miliseconds delay between repeatable animations. If repeat option is set to 0, will produce no effect. The default value is 0.

-

yoyo: true/false option makes use of the internal reverse functionality to also animate from end to start for a given tween. This option requires that you use the repeat option with at least value 1. The default value is false.

-

easing: 'easingCubicInOut' option allows you to use a custom easing function for your animation. For more info on the easing functions, you need to see the example pages. The default value is linear.

- -

Transform Options

-

These options only affect animation involving any property from CSS3 transform specs and have no effect on other CSS properties. While you can set perspective or perspective origin via CSS, these options are here to help, especially with full browser support and preffix free handling.

-

perspective: 500 option allows you to set a 3D transformation perspective for a given HTML element that is subject to transform animation. No default value.

-

perspectiveOrigin: "50% 50%" option allows you to set a perspectiveOrigin for a given HTML. This option has no default value and only accepts valid CSS values according to it's specs.

-

parentPerspective: 500 option allows you to set a 3D perspective for the parent of the HTML element subject to the transform animation.

-

parentPerspectiveOrigin: "50% 50%" option allows you to set a perspectiveOrigin for the parent of the HTML element subject to the transform animation. Also like the above similar options, this options only accepts valid CSS values.

-

transformOrigin: "50% 50%" option allows you to set a transformOrigin for the HTML element subject to the transform animation. Also this options only accepts valid CSS values.

- -

Callback Options

-

These options also affect all types of tweens, and are bound by the tween control options and the internal update functions.

-

start: function option allows you to set a function to run once tween animation starts.

-

update: function option allows you to set a function to run on every frame.

-

pause: function option allows you to set a function to run when animation is paused.

-

resume: function option allows you to set a function to run when animation is resumed.

-

stop: function option allows you to set a function to run when animation is stopped.

-

complete: function option allows you to set a function to run when animation is finished.

-

A quick example would look like this:

-
//define a function
-var callback = function(){
-	//do some foo
-}
-
-//create object and start animating already
-KUTE.fromTo(div,{left:150},{left:0},{complete: callback}).start();
-
-

Other

-

keepHex: true option allows you to always use HEX color format, even if you have used RGB or RGBA. This option is useful when tweening color properties on legacy browsers, however modern browsers may ignore this option for performance reasons.

-
- -
-

Easing Functions

-

The easing functions generally make animations closer to reality and completely eliminate the boring factor for a given context. The most simple example to understand what they do, think of gravity. Dropping an object from a given height, will start moving to the ground with accelerated speed. If the object has some sort of bounciness like a ball, it will jump back up and up again, till the gravity will eventually stick the object to the ground.

-

What scientists observed and put in theory houndreads of years ago, later the pioneers of scripting started to implement the laws of physics into digital animation and came up with this notion of easing to describe the progression of movement. If you care to dig into the concept, here's an excellent resource some developers recommend. I would also recommend this one too.

- -

Core Functions

-

Modern browsers that support transition can also make use of some generic easing functions via the CSS3 transition-timing-function:ease-out property, but in Javascript animation, we need some special functions. The popular Robert Penner's easing functions set is one of them, and is the default set included with KUTE.js because it's the fastest set I know in terms of performance. Some functions may lack a bit of accuracy but they cover the most animation needs. Generally the easing functions' names are built with keywords that describe the type of easing, like circular or exponential, and also the type of progression in and/or out.

- -

To use them, simply set a tween option like so easing: KUTE.Easing.easingSinusoidalInOut or simply easing: 'easingSinusoidalInOut'.

-

linear is the default easing function and just as it sounds, it means that the animation has no acceleration or deceleration over time. While this one is basically boring, it's the fastest in all, and it's very useful when animating opacity or colors because we cannot really distinguish changes in speed for such cases, but mostly for movement.

- -

curve based functions are the next set of easings we are going to tak about. They are basically the same, the only difference is the number of multipliers applied (better think of it like the more weight an object has, the more acceleration):

-
    -
  • Sinusoidal - multiplier of 1 (super light object, like a feather)
  • -
  • Quadratic - multiplier of 2
  • -
  • Cubic - multiplier of 3
  • -
  • Quartic - multiplier of 4
  • -
  • Quintic - multiplier of 5
  • -
  • Circular - multiplier of 6
  • -
  • Exponential - multiplier of 10 (super heavy object, like a truck)
  • -
- -

The In / Out explained:

-
    -
  • In - means that the animation starts with very very low speed and gains acceleration over time, but when it reaches the maximum speed, animation stops. These functions are: easingSinusoidalIn, easingQuadraticIn,easingCubicIn, easingQuarticIn, easingQuinticIn, easingCircularIn and easingExponentialIn.
  • -
  • Out - means that the animation starts with maximum speed and constantly decelerates over time until the animation stops. These functions are: easingSinusoidalOut, easingQuadraticOut, easingCubicOut, easingQuarticOut, easingQuinticOut, easingCircularOut and easingExponentialOut.
  • -
  • InOut - means that the animation accelerates halfway until it reaches the maximum speed, then begins to decelerate until it stops. These functions are: easingSinusoidalInOut, easingQuadraticInOut, easingCubicInOut, easingQuarticInOut, easingQuinticInOut, easingCircularInOut and easingExponentialInOut.
  • -
- -

back easing functions describe more complex animations (I would call them reverse gravity easings). They also come with in and/or out types of progression.

-
    -
  • easingBackIn would be best described when you throw an object into the air with a small amount of physical power, it will move up decelerating until it stops, then will move to the grund with acceleration.
  • -
  • easingBackOut would be best described as the previous function, but viewed in reverse mode.
  • -
  • easingBackInOut is a combination of the other two.
  • -
- -

elasticity easing functions describe the kind of animation where the object is elastic. With in and/or out as well.

-
    -
  • easingElasticOut would be best described by the movement of a guitar string after being pinched, moving up and down, with decreasing frequency, until it stops.
  • -
  • easingElasticIn would be best described as the above function but viewed in reverse mode.
  • -
  • easingElasticInOut is simply a combination of the other two.
  • -
- -

gravity based easing functions describe the kind of animation where the object has a certain degree of bounciness, like a ball. With in and/or out as well.

-
    -
  • easingBounceOut looks just like a ball falling on the ground and start boucing up and down with decreasing frequency untill it stops.
  • -
  • easingBounceIn looks like the previous viewed in reverse mode
  • -
  • easingBounceInOut is a combination of the other two.
  • -
- -

Cubic Bezier Functions

-

While modern browsers support CSS3 transition with transition-timing-function: cubic-bezier(0.1,0.5,0.8,0.5), in Javascript animation we need some specific functions to cover that kind of functionality. As mentioned in the features page, we are using a modified version of the cubic-bezier by Gaëtan Renaudeau. I believe this must be most accurate easing functions set.

-

You can use them either with easing: KUTE.Ease.bezier(mX1, mY1, mX2, mY2) or easing: 'bezier(mX1, mY1, mX2, mY2)', where mX1, mY1, mX2, mY2 are Float values from 0 to 1. You can find the right values you need right here.

-

There is also a pack of presets, and the keywords look very similar if you have used jQuery.Easing plugin before:

-
    -
  • Equivalents of the browser's generic timing functions: easeIn, easeOut and easeInOut
  • -
  • Sinusoidal timing functions: easeInSine, easeOutSine and easeInOutSine
  • -
  • Quadratic timing functions: easeInQuad, easeOutQuad and easeInOutQuad
  • -
  • Cubic timing functions: easeInCubic, easeOutCubic and easeInOutCubic
  • -
  • Quartic timing functions: easeInQuart, easeInQuart and easeInOutQuart
  • -
  • Quintic timing functions: easeInQuint, easeOutQuint and easeInOutQuint
  • -
  • Exponential timing functions: easeInExpo, easeOutExpo and easeInOutExpo
  • -
  • Back timing functions: easeInBack, easeOutBack and easeInOutBack
  • -
  • Special slow motion timing functions look like this: slowMo, slowMo1 and slowMo2
  • -
- -

Physics Based Functions

-

KUTE.js also packs the dynamics physics easing functions by Michael Villar and I have to say these functions are amazing in terms of flexibility, control and performance. They allow you to control the friction, bounciness, frequency, elasticity, or multiple bezier points for your animations.

-

You can use them either with regular Javascript invocation as shown below and configure / visualize them on the author's website, while you can also use the pack of presets featuring mostly bezier based functions. Ok now, let's get to it:

- -
    -
  • spring function is basically an elastic type of easing that allows you to set frequency:1-1000, friction:1-1000, anticipationSize:0-1000 (a kind of delay in miliseconds) and anticipationStrength:0-1000 (a kind of a new curve to add to the function while waiting the anticipationSize). Usage: easing: KUTE.Physics.spring({friction:100,frequency:600}).
  • -
  • bounce function is also an elastic easing function, but it works different than Robert Penner's version that's basically a gravity based function. This one here will always come back to the starting values. This function allows you to set frequency:0-1000 and friction:0-1000. Usage: easing: KUTE.Physics.bounce({friction:100,frequency:600}).
  • -
  • gravity function does what a ball dropped on the ground does, bounces until it stops. It allows you to set: elasticity:1-1000 and bounciness:0-1000. Usage: easing: KUTE.Physics.gravity({elasticity:100,bounciness:600}).
  • -
  • forceWithGravity function acts just like gravity except that the ball instead of being dropped it's thrown into the air. This allows you to set same options: elasticity:1-1000 and bounciness:0-1000. Usage: easing: KUTE.Physics.forceWithGravity({elasticity:100,bounciness:600}).
  • -
  • bezier easing function is a bit more complicated as it allows you to set multiple points of bezier curves. Usage: easing: KUTE.Physics.bezier({points:POINTS_ARRAY_COMES HERE}), again use the author's website, edit the bezier curve as you wish and copy paste the points array into this function. Here's how a basic easeIn looks like: -
    // sample bezier based easing setting
    -easing: KUTE.Physics.bezier({points: [{"x":0,"y":0,"cp":[{"x":0.483,"y":0.445}]},{"x":1,"y":1,"cp":[{"x":0.009,"y":0.997}]}] })
    -
    -
  • -
-

The presets can be used both as a string easing:'physicsIn' or easing:KUTE.Physics.physicsIn(friction:200). The list is:

-
    -
  • curves: physicsIn, physicsOut, physicsInOut can do all multipliers (from sinusoidal to exponential) via the friction option;
  • -
  • back: physicsBackIn, physicsBackOut, physicsBackInOut also benefit from the friction option.
  • -
- - - -
- - - - -
- - - - - - - - - - - - - - - diff --git a/demo/assets/css/kute.css b/demo/assets/css/kute.css deleted file mode 100644 index 6689962..0000000 --- a/demo/assets/css/kute.css +++ /dev/null @@ -1,345 +0,0 @@ -/*! - * KUTE.js | https://github.com/thednp/kute.js/ - * Licensed under MIT (https://github.com/thednp/kute.js/blob/master/LICENSE) - */ - -/* GLOBAL STYLES --------------------------------------------------- */ -body { - font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; - font-size: 14px; - line-height: 2; /* ~25px */ - color: #ddd; - background-color: #999; - position: relative - -} - -body > .fill { - position: fixed; top: 0; left:0; right: 0; bottom:0; -} - -.fill { - background-size: cover; - background-position: 50% 50%; - background-repeat: no-repeat; - width: 100%; height: 100%; -} -.ie8 .fill {background-size: auto 100%} - -.overlay { - background-color: #000; - opacity: 0.7 -} - -.ie8 .overlay { filter: alpha(opacity=70) } - -footer { - clear: both; overflow: hidden; margin-top: 60px -} - -footer .content-wrap { - padding-top: 5px; - border-top: 1px solid rgb(120,120,120); border-top: 1px solid rgba(255,255,255,0.2); -} - -footer p {margin: 0 0 10px} - -/* site-wrapper */ -.site-wrapper { position: relative; overflow: hidden} - -/* navbar */ -.navbar-wrapper { position: relative; clear: both } -.navbar-wrapper .content-wrap { height: 64px; padding: 20px 0 0; } - -.navbar-wrapper h1 { color: #fff; font-size: 32px; line-height: 25px; letter-spacing: -2px; float: left; padding-right: 25px; margin-right: 25px; border-right: 1px solid rgb(120,120,120); border-right: 1px solid rgba(255,255,255,0.2) } -.navbar-wrapper h1 span { font-size: 24px; color: #555; letter-spacing: -1px; } -.navbar-wrapper h1.active span { color: #ffd626 } -.navbar-wrapper .nav { float: left; padding: 0 0 18px; margin: 0; border-bottom: 1px solid #555 } -.nav li { float: left; display: block; line-height: 25px; list-style: none } -.nav li:not(:last-child) { margin-right: 12px } -.ie8 .nav li { margin-right: 12px } -.nav li.active a { color: #ffd626 } -.nav li a { color: #ccc } -@media (max-width: 768px){ - .navbar-wrapper .content-wrap { height: 94px} - .navbar-wrapper h1 {border: 0} - .navbar-wrapper .nav, - .navbar-wrapper h1 { float: none; } - .navbar-wrapper .nav { height: 30px } -} - -.ie8 .btn.top-right { top:55px } - -/* featurettes */ -.featurettes { -background: #222; - padding: 60px 0; - width: 100%; - clear: both; - margin: 60px 0; - float: left; -} - -.content-wrap .featurettes { margin: 0 0 20px; padding: 20px 0 0 20px; display: inline-block; border-radius: 10px; position: relative } - -/* example box */ -.example-box { - font-size: 40px; line-height: 150px; text-align:center; font-weight: bold; - width: 150px; height: 150px; float: left; position:relative; - border-radius: 5px; margin: 0 20px 20px 0; -/* easy hack to improve box model properties performance on modern browsers only ofc */ - transform: translate3d(0px,0px,0px); -webkit-transform: translate3d(0px,0px,0px); -} -.example-buttons {position: absolute; top: 18px; right:0} - -/* text properties example */ -h1.example-item { - font-size: 50px; - line-height:50px; - color: #fff; -} - -h1.example-item span { - line-height: inherit; - opacity: 0; display: inline; - vertical-align: top; -} -.btn.example-item {opacity: 0} - -.ie8 h1.example-item span, -.ie8 .btn.example-item {filter: alpha(opacity=0)} -/*.ie8 .btn.example-item * {filter: inherit}*/ - -/* UTILITY STYLES --------------------------------------------------- */ -.clearfix:before, -.clearfix:after { - content: " "; - display: table; -} -.clearfix:after { - clear: both; -} -.center-block { - display: block; - margin-left: auto; - margin-right: auto; -} -.pull-right { - float: right !important; -} -.pull-left { - float: left !important; -} -.hide { - display: none !important; -} -.show { - display: block !important; -} -.invisible { - visibility: hidden; -} -.text-hide { - font: 0/0 a; - color: transparent; - text-shadow: none; - background-color: transparent; - border: 0; -} -.hidden { - display: none !important; - visibility: hidden !important; -} - -.hiddenoverflow { overflow: hidden } - -.media {float: left; margin: 5px 20px 0 0; height: auto; font-size: 64px; line-height: 64px; width: 64px; text-align: center} - - -/* WRAPPER STYLES --------------------------------------------------- */ -.content-wrap { position: relative; width: 980px; margin: 0 auto; max-width: 100%; clear: both; } -@media (max-width: 1200px){ - .content-wrap { width: 100%; max-width: 80%; } -} - -/* check div consistency -div { background-color: rgba(0,0,0,0.2) }*/ - -/* TYPO STYLES --------------------------------------------------- */ -p, ul, ol { margin: 0 0 20px } -h1, h2, h3, h4, strong {color: #ffd626} -h1 { font-size: 54px; letter-spacing:-3px; line-height: 0.92; font-weight: normal; } -h2 { font-size: 46px; letter-spacing:-2px; line-height: 1.08; font-weight: normal; margin: 1.08em 0 0.27em; width: 100%; } -h3 { font-size: 24px; letter-spacing:0px; line-height: 0.96; font-weight: normal; } -h4 { font-size: 16px; letter-spacing:0px; line-height: 1.14; font-weight: normal; } -h1, h3, [class*="col"] > h4 {margin: 0 0 20px} - -.lead { font-size: 16px } - -.nomargin { margin-top: 0px !important } -@media (min-width: 768px){ - .nomarginlarge { margin-top: 0 !important } -} - -/* COLUMN STYLES --------------------------------------------------- */ -.columns { position: relative; width: auto; margin: 0 -20px; clear: both } -.columns > [class*="col"] { padding: 0 20px; float:left; position: relative } -.col2 { width: 50% } -.col3 { width: 33.3% } -.col4 { width: 25% } -.col8 { width: 75% } - -@media (min-width: 480px) and (max-width: 768px){ - /*.columns:not(#blocks) .col3:last-child{width: 100%;}*/ - .col3, - .col4 { width: 50% } - .col8 { width: 100% } -} -@media (max-width: 479px){ - .columns > [class*="col"] { float:none; width: 100%; } -} - -.table { display: table; height: 480px } -.cell { display: table-cell; vertical-align: middle } - -@media (max-width: 479px){ - .table { height: 320px } -} - -/* welcome */ -.col3.bg { /*min-height: 120px;*/ width: 32%; margin: 1.3% 1.3% 0 0; float: left; padding: 0; opacity:0 } -.ie8 .col3.bg { filter: alpha(opacity=0); } - -.col3.bg:nth-child(3), -.col3.bg:nth-child(6), -.col3.bg:nth-child(9) { margin: 1.3% 0 0 } - -.welcome > .table > .cell {perspective: 600px; -webkit-perspective: 600px; } -#blocks { - transform: rotateY(-10deg); -webkit-transform: rotateY(-10deg); width: 90%; -} - -/*.replay { display: none; }*/ - -@media (max-width: 768px){ - .columns.welcome .col2.table { width: 100% !important; float: left } - .columns.welcome .col2:nth-child(2) { position: absolute; top: 0; z-index: -1 } - #blocks { width: auto } -} - -/* STYLING CONTENT --------------------------------------------------- */ -/* images */ -img { max-width: 100% } -img.circle { border-radius: 50% } - -/* links */ -a { - color: #ffd626; - text-decoration: none; -} -a:hover, -a:focus { - color: #4CAF50; - text-decoration: underline; -} -a:focus { - outline: none; -} - -hr { - border: 1px solid #444; - margin: 10px 0; -} - -/* share */ -#share {position: fixed; top: 20px;right: 20px;} -#share .icon {font-size: 24px; line-height: 1} - -/* buttons */ -.btn { padding: 12px 15px; color:#fff; border:0; background-color: #999; line-height: 44px; } -.bg-gray { color:#fff; background-color: #555; } -.btn.active { background-color: #2196F3 } -.btn:hover, .btn:active, .btn:focus { color: #fff; text-decoration: none; background-color: #777} -.btn-olive, .bg-olive {background-color: #9C27B0; color: #fff} .btn-olive:hover, .btn-olive:active, .btn-olive:focus { background-color: #673AB7 } -.btn-indigo, .bg-indigo { background-color: #673AB7; color: #fff} .btn-indigo:hover, .btn-indigo:active, .btn-indigo:focus { background-color: #ffd626; color:#000 } -.btn-green, .bg-green { background-color: #4CAF50; color: #fff} .btn-green:hover, .btn-green:active, .btn-green:focus { background-color: #9C27B0 } -.btn-red, .bg-red { background-color: #e91b1f; color: #fff} .btn-red:hover, .btn-red:active, .btn-red:focus { background-color: #4CAF50 } -.btn-yellow, .bg-yellow { background-color: #ffd626; color:#000} .btn-yellow:hover, .btn-yellow:active, .btn-yellow:focus { background-color: #4CAF50; color: #000 } -.btn-blue, .bg-blue { background-color: #2196F3; color: #fff} .btn-blue:hover, .btn-blue:active, .btn-blue:focus { background-color: #e91b1f } -.btn-pink, .bg-pink { background-color: #E91E63; color: #fff} .btn-pink:hover, .btn-pink:active, .btn-pink:focus { background-color: #2196F3 } -.btn-orange, .bg-orange { background-color: #FF5722; color: #fff} .btn-orange:hover, .btn-orange:active, .btn-orange:focus { background-color: #4CAF50 } -.btn-lime, .bg-lime { background-color: #CDDC39; color: #000} .btn-lime:hover, .btn-lime:active, .btn-lime:focus { background-color: #e91b1f } -.btn-teal, .bg-teal { background-color: #009688; color: #fff} .btn-teal:hover, .btn-teal:active, .btn-teal:focus { background-color: #9C27B0 } - -.icon-large { font-size: 78px; line-height: 0.64; text-shadow: 2px 2px 0 #FFF,3px 3px 0px #ccc;} -.icon-large.fa-cogs:before { color: #4CAF50 } -.icon-large.fa-rocket:before { color: #673AB7 } -.icon-large.fa-code-fork:before { color: #9C27B0 } - -.btn span { - font-size: 150%; - vertical-align: middle; -} - -.btn span.right { margin: 0 0 0 10px } -.btn span.left { margin: 0 10px 0 0 } - - -/* STYLE CODE WRAPPING --------------------------------------------------- */ -code, kbd, pre { - font-family: Menlo,Monaco,Consolas,"Courier New",monospace; -} -pre { - display: block; - padding: 10px 15px !important; - margin: 0 0 20px !important; - line-height: 2.08; - color: #999; - word-break: break-all; - background-color: rgb(33,33,33); - background-color: rgba(11,11,11,0.5); - /*border: 1px solid rgb(22,22,22); - border: 1px solid rgba(11,11,11,0.8);*/ - border-radius: 4px; - text-align: left; - position: relative; -} -pre.language-javascript:after, -pre.language-clike:after, -pre.language-markup:after { - position: absolute; top:0; right:0; padding: 2px 5px; - background: #000; - border-radius: 0px 0px 0px 5px; - font-family: Helvetica, Arial, sans-serif; - font-size: 12px; color: #999; -} - -pre.language-javascript:after {content: 'Javascript';} -pre.language-clike:after {content: 'node';} -pre.language-markup:after {content: 'HTML';} -pre code {background: none;padding: 0; font-weight: normal; font-size: 100%;} -code { - padding: 2px 4px; - font-size: 90%; - color: #999; - background-color: #111; - border-radius: 4px; - white-space: pre; - font-weight: bold -} - -kbd { - padding: 2px 4px; - font-size: 90%; - color: #333; - background-color: #eee; - border-radius: 3px; - font-weight: bold -} \ No newline at end of file diff --git a/demo/assets/css/prism.css b/demo/assets/css/prism.css deleted file mode 100644 index c7ced87..0000000 --- a/demo/assets/css/prism.css +++ /dev/null @@ -1,3 +0,0 @@ - /* prism okaidia | ocodia */ - -code[class*=language-],pre[class*=language-]{color:#f8f8f2;text-shadow:0 1px rgba(0,0,0,.3);font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;direction:ltr;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto;border-radius:.3em}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em}.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#708090}.token.punctuation{color:#f8f8f2}.namespace{opacity:.7}.token.constant,.token.deleted,.token.property,.token.symbol,.token.tag{color:#f92672}.token.boolean,.token.number{color:#ae81ff}.token.attr-name,.token.builtin,.token.char,.token.inserted,.token.selector,.token.string{color:#a6e22e}.language-css .token.string,.style .token.string,.token.entity,.token.operator,.token.url,.token.variable{color:#f8f8f2}.token.atrule,.token.attr-value,.token.function{color:#e6db74}.token.keyword{color:#66d9ef}.token.important,.token.regex{color:#fd971f}.token.bold,.token.important{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help} \ No newline at end of file diff --git a/demo/assets/css/reset.css b/demo/assets/css/reset.css deleted file mode 100644 index af84377..0000000 --- a/demo/assets/css/reset.css +++ /dev/null @@ -1,209 +0,0 @@ -/*! normalize.css v3.0.1 | MIT License | git.io/normalize */ -html { - font-family: sans-serif; - -ms-text-size-adjust: 100%; - -webkit-text-size-adjust: 100%; -} -body { - margin: 0; -} -article, -aside, -details, -figcaption, -figure, -footer, -header, -hgroup, -main, -nav, -section, -summary { - display: block; -} -audio, -canvas, -progress, -video { - display: inline-block; - vertical-align: baseline; -} -audio:not([controls]) { - display: none; - height: 0; -} -[hidden], -template { - display: none; -} -a { - background: transparent; -} -a:active, -a:hover { - outline: 0; -} -abbr[title] { - border-bottom: 1px dotted; -} -b, -strong { - font-weight: bold; -} -dfn { - font-style: italic; -} -h1 { - font-size: 2em; - margin: 0.67em 0; -} -mark { - background: #ff0; - color: #000; -} -small { - font-size: 80%; -} -sub, -sup { - font-size: 75%; - line-height: 0; - position: relative; - vertical-align: baseline; -} -sup { - top: -0.5em; -} -sub { - bottom: -0.25em; -} -img { - border: 0; -} -svg:not(:root) { - overflow: hidden; -} -figure { - margin: 1em 40px; -} -hr { - -moz-box-sizing: content-box; - box-sizing: content-box; - height: 0; -} -pre { - overflow: auto; -} -code, -kbd, -pre, -samp { - font-family: monospace, monospace; - font-size: 1em; -} -button, -input, -optgroup, -select, -textarea { - color: inherit; - font: inherit; - margin: 0; -} -button { - overflow: visible; -} -button, -select { - text-transform: none; -} -button, -html input[type="button"], -input[type="reset"], -input[type="submit"] { - -webkit-appearance: button; - cursor: pointer; -} -button[disabled], -html input[disabled] { - cursor: default; -} -button::-moz-focus-inner, -input::-moz-focus-inner { - border: 0; - padding: 0; -} -input { - line-height: normal; -} -input[type="checkbox"], -input[type="radio"] { - box-sizing: border-box; - padding: 0; -} -input[type="number"]::-webkit-inner-spin-button, -input[type="number"]::-webkit-outer-spin-button { - height: auto; -} -input[type="search"] { - -webkit-appearance: textfield; - -moz-box-sizing: content-box; - -webkit-box-sizing: content-box; - box-sizing: content-box; -} -input[type="search"]::-webkit-search-cancel-button, -input[type="search"]::-webkit-search-decoration { - -webkit-appearance: none; -} -fieldset { - border: 1px solid #c0c0c0; - margin: 0 2px; - padding: 0.35em 0.625em 0.75em; -} -legend { - border: 0; - padding: 0; -} -textarea { - overflow: auto; -} -optgroup { - font-weight: bold; -} -table { - border-collapse: collapse; - border-spacing: 0; -} -td, -th { - padding: 0; -} -* { - -webkit-box-sizing: border-box; - -moz-box-sizing: border-box; - box-sizing: border-box; -} -*:before, -*:after { - -webkit-box-sizing: border-box; - -moz-box-sizing: border-box; - box-sizing: border-box; -} -html { - font-size: 10px; - -webkit-tap-highlight-color: rgba(0, 0, 0, 0); -} -input, -button, -select, -textarea { - font-family: inherit; - font-size: inherit; - line-height: inherit; -} -figure { - margin: 0; -} -img { - /*vertical-align: middle;*/ -} \ No newline at end of file diff --git a/demo/assets/img/favicon.png b/demo/assets/img/favicon.png deleted file mode 100644 index 7737268..0000000 Binary files a/demo/assets/img/favicon.png and /dev/null differ diff --git a/demo/assets/img/img-blank.gif b/demo/assets/img/img-blank.gif deleted file mode 100644 index 5891de4..0000000 Binary files a/demo/assets/img/img-blank.gif and /dev/null differ diff --git a/demo/assets/img/loader.gif b/demo/assets/img/loader.gif deleted file mode 100644 index 335e00c..0000000 Binary files a/demo/assets/img/loader.gif and /dev/null differ diff --git a/demo/assets/js/examples.js b/demo/assets/js/examples.js deleted file mode 100644 index c7b7a12..0000000 --- a/demo/assets/js/examples.js +++ /dev/null @@ -1,356 +0,0 @@ -// some regular checking -var isIE = (new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})").exec(navigator.userAgent) != null) ? parseFloat( RegExp.$1 ) : false, - isIE8 = isIE === 8, - isIE9 = isIE === 9; - - - -/* TRANSFORMS EXAMPLES */ -var featurettes = document.querySelectorAll('.featurettes'), fl = featurettes.length; - -for ( var i=0; i0 && op[i]!==undefined) { - op[i] = op[i].charAt(0).toUpperCase() + op[i].slice(1); - } - } - op = op.join(''); - options[op] = attr[l].value; - } else if (/property/.test(attr[l].nodeName)) { - var pp = attr[l].nodeName.replace('data-property-','').replace(/\s/,'').split('-'); - for (var j=0;j0 && pp[j]!==undefined) { - pp[j] = pp[j].charAt(0).toUpperCase() + pp[j].slice(1); - } - } - pp = pp.join(''); - properties[pp] = pp === 'translate3d' || pp === 'translate' ? attr[l].value.replace(/\[|\]/g,'').split(',') : attr[l].value; - } - } - } - return {options: options, properties: properties}; -} -/* TRANSFORMS EXAMPLES */ - - -/* CHAINED TWEENS EXAMPLE */ -var chainedTweens = document.getElementById('chainedTweens'), - el1 = chainedTweens.querySelectorAll('.example-item')[0], - el2 = chainedTweens.querySelectorAll('.example-item')[1], - el3 = chainedTweens.querySelectorAll('.example-item')[2], - ctb = chainedTweens.querySelector('.btn'); - -// built the tween objects for element1 -var tween11 = KUTE.fromTo(el1, {translateX:0, rotateX: 0}, {translateX:100, rotateX: 25}, {perspective:100, duration: 2000}); -var tween12 = KUTE.fromTo(el1, {translateY:0, rotateY: 0}, {translateY:20, rotateY: 15}, {perspective:100, duration: 2000}); -var tween13 = KUTE.fromTo(el1, {translate3d:[100,20,0], rotateX: 25, rotateY:15}, {translate3d:[0,0,0], rotateX: 0, rotateY:0}, {perspective:100, duration: 2000}); - -// chain tweens -tween11.chain(tween12); -tween12.chain(tween13); - -// built the tween objects for element2 -var tween21 = KUTE.fromTo(el2, {translateX:0, translateY:0, rotateX: 0, rotateY:0 }, {translateX:150, translateY:0, rotateX: 25, rotateY:0}, {perspective:100, duration: 2000}); -var tween22 = KUTE.fromTo(el2, {translateX:150, translateY:0, rotateX: 25, rotateY: 0}, {translateX:150, translateY:20, rotateX: 25, rotateY: 15}, {perspective:100, duration: 2000}); -var tween23 = KUTE.fromTo(el2, {translate3d:[150,20,0], rotateX: 25, rotateY:15}, {translate3d:[0,0,0], rotateX: 0, rotateY:0}, {perspective:100, duration: 2000}); - -// chain tweens -tween21.chain(tween22); -tween22.chain(tween23); - -// built the tween objects for element3 -var tween31 = KUTE.to(el3,{translateX:200, rotateX: 25}, {perspective:100, duration: 2000}); -var tween32 = KUTE.to(el3,{translate3d:[200,20,0], rotateY: 15}, {perspective:100, duration: 2000}); -var tween33 = KUTE.to(el3,{translate3d:[0,0,0], rotateX: 0, rotateY:0}, {perspective:100, duration: 2000}); - -// chain tweens -tween31.chain(tween32); -tween32.chain(tween33); - -ctb.addEventListener('click',function(e){ - e.preventDefault(); - tween11.start(); tween21.start(); tween31.start(); -},false); -/* CHAINED TWEENS EXAMPLE */ - - -/* BOX MODEL EXAMPLE */ -var boxModel = document.getElementById('boxModel'), - btb = boxModel.querySelector('.btn'), - box = boxModel.querySelector('.example-box'); - -// built the tween objects -var bm1 = KUTE.to(box,{width:250},{ yoyo: true, repeat: 1, duration: 1500, update: onWidth}); -var bm2 = KUTE.to(box,{height:250},{ yoyo: true, repeat: 1, duration: 1500, update: onHeight}); -var bm3 = KUTE.to(box,{left:250},{ yoyo: true, repeat: 1, duration: 1500, update: onLeft}); -var bm4 = KUTE.to(box,{top:-250},{ yoyo: true, repeat: 1, duration: 1500, update: onTop}); -var bm5 = KUTE.fromTo(box,{padding:0},{padding:20},{ yoyo: true, repeat: 1, duration: 1500, update: onPadding}); -var bm6 = KUTE.to(box,{marginTop:50,marginLeft:50,marginBottom:70},{ yoyo: true, repeat: 1, duration: 1500, update: onMargin, complete: onComplete}); - -// chain the bms -bm1.chain(bm2); -bm2.chain(bm3); -bm3.chain(bm4); -bm4.chain(bm5); -bm5.chain(bm6); - -//callback functions -function onWidth() { var css = box.currentStyle || window.getComputedStyle(box); box.innerHTML = 'WIDTH
'+parseInt(css.width)+'px'; } -function onHeight() { var css = box.currentStyle || window.getComputedStyle(box); box.innerHTML = 'HEIGHT
'+parseInt(css.height)+'px'; } -function onLeft() { var css = box.currentStyle || window.getComputedStyle(box); box.innerHTML = 'LEFT
'+parseInt(css.left)+'px'; } -function onTop() { var css = box.currentStyle || window.getComputedStyle(box); box.innerHTML = 'TOP
'+parseInt(css.top)+'px'; } -function onPadding() { var css = box.currentStyle || window.getComputedStyle(box); box.innerHTML = 'PADDING
'+(parseInt(css.padding)+'px')||'auto'; } -function onMargin() { var css = box.currentStyle || window.getComputedStyle(box); box.innerHTML = 'MARGIN
'+parseInt(css.marginTop)+'px'; } -function onComplete() { box.innerHTML = 'BOX
MODEL'; btb.style.display='inline'; } - -btb.addEventListener('click', function(e){ - e.preventDefault(); - bm1.start(); - btb.style.display='none'; -},false); -/* BOX MODEL EXAMPLE */ - - -/* TEXT PROPERTIES EXAMPLE */ -var textProperties = document.getElementById('textProperties'), - heading = textProperties.querySelector('h1'), - button = textProperties.querySelectorAll('.btn')[0], - tbt = textProperties.querySelectorAll('.btn')[1], - - // let's split the heading text by character - chars = heading.innerHTML.split(''); - -// wrap the splits into spans and build an object with these spans -heading.innerHTML = '' + chars.join('') + ''; -var charsObject = heading.getElementsByTagName('SPAN'), l = charsObject.length; - - -// built the tween objects -var tp1 = KUTE.fromTo( - button, - {width: 150, opacity:0, height: 70, lineHeight:70, fontSize: 40}, - {width: 100, opacity:1, height: 35, lineHeight:35, fontSize: 20}); - -function runHeadingAnimation() { - for (var i=0; i - function CSSStyleDeclaration(element) { - var style = this, - currentStyle = element.currentStyle, - fontSize = getComputedStylePixel(element, 'fontSize'), - unCamelCase = function (match) { - return '-' + match.toLowerCase(); - }, - property; - - for (property in currentStyle) { - Array.prototype.push.call(style, property == 'styleFloat' ? 'float' : property.replace(/[A-Z]/, unCamelCase)); - - if (property == 'width') { - style[property] = element.offsetWidth + 'px'; - } else if (property == 'height') { - style[property] = element.offsetHeight + 'px'; - } else if (property == 'styleFloat') { - style.float = currentStyle[property]; - } else if (/margin.|padding.|border.+W/.test(property) && style[property] != 'auto') { - style[property] = Math.round(getComputedStylePixel(element, property, fontSize)) + 'px'; - } else if (/^outline/.test(property)) { - // errors on checking outline - try { - style[property] = currentStyle[property]; - } catch (error) { - style.outlineColor = currentStyle.color; - style.outlineStyle = style.outlineStyle || 'none'; - style.outlineWidth = style.outlineWidth || '0px'; - style.outline = [style.outlineColor, style.outlineWidth, style.outlineStyle].join(' '); - } - } else { - style[property] = currentStyle[property]; - } - } - - setShortStyleProperty(style, 'margin'); - setShortStyleProperty(style, 'padding'); - setShortStyleProperty(style, 'border'); - - style.fontSize = Math.round(fontSize) + 'px'; - } - - CSSStyleDeclaration.prototype = { - constructor: CSSStyleDeclaration, - // .getPropertyPriority - getPropertyPriority: function () { - throw new Error('NotSupportedError: DOM Exception 9'); - }, - // .getPropertyValue - getPropertyValue: function (property) { - return this[property.replace(/-\w/g, function (match) { - return match[1].toUpperCase(); - })]; - }, - // .item - item: function (index) { - return this[index]; - }, - // .removeProperty - removeProperty: function () { - throw new Error('NoModificationAllowedError: DOM Exception 7'); - }, - // .setProperty - setProperty: function () { - throw new Error('NoModificationAllowedError: DOM Exception 7'); - }, - // .getPropertyCSSValue - getPropertyCSSValue: function () { - throw new Error('NotSupportedError: DOM Exception 9'); - } - }; - - // .getComputedStyle - window.getComputedStyle = function getComputedStyle(element) { - return new CSSStyleDeclaration(element); - }; - })(); -} - -// requestAnimationFrame -if (!window.requestAnimationFrame) { - - var lT = Date.now(); // lastTime - window.requestAnimationFrame = function (callback) { - 'use strict'; - if (typeof callback !== 'function') { - throw new TypeError(callback + 'is not a function'); - } - - var cT = Date.now(), // currentTime - dl = 16 + lT - cT; // delay - - if (dl < 0) { dl = 0; } - - lT = cT; - - return setTimeout(function () { - lT = Date.now(); - callback(window.performance.now()); - }, dl); - }; - - window.cancelAnimationFrame = function (id) { - clearTimeout(id); - }; -} - - -// Event -if (!window.Event||!Window.prototype.Event) { - (function (){ - window.Event = Window.prototype.Event = Document.prototype.Event = Element.prototype.Event = function Event(t, args) { - if (!t) { throw new Error('Not enough arguments'); } // t is event.type - var ev, - b = args && args.bubbles !== undefined ? args.bubbles : false, - c = args && args.cancelable !== undefined ? args.cancelable : false; - if ( 'createEvent' in document ) { - ev = document.createEvent('Event'); - ev.initEvent(t, b, c); - } else { - ev = document.createEventObject(); - ev.type = t; - ev.bubbles = b; - ev.cancelable = c; - } - return ev; - }; - })(); -} - -// CustomEvent -if (!('CustomEvent' in window) || !('CustomEvent' in Window.prototype)) { - (function(){ - window.CustomEvent = Window.prototype.CustomEvent = Document.prototype.CustomEvent = Element.prototype.CustomEvent = function CustomEvent(type, args) { - if (!type) { - throw Error('TypeError: Failed to construct "CustomEvent": An event name must be provided.'); - } - var ev = new Event(type, args); - ev.detail = args && args.detail || null; - return ev; - }; - - })() -} - -// addEventListener -if (!window.addEventListener||!Window.prototype.addEventListener) { - (function (){ - window.addEventListener = Window.prototype.addEventListener = Document.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener() { - var el = this, // element - t = arguments[0], // type - l = arguments[1]; // listener - - if (!el._events) { el._events = {}; } - - if (!el._events[t]) { - el._events[t] = function (e) { - var ls = el._events[e.type].list, evs = ls.slice(), i = -1, lg = evs.length, eE; // list | events | index | length | eventElement - - e.preventDefault = function preventDefault() { - if (e.cancelable !== false) { - e.returnValue = false; - } - }; - - e.stopPropagation = function stopPropagation() { - e.cancelBubble = true; - }; - - e.stopImmediatePropagation = function stopImmediatePropagation() { - e.cancelBubble = true; - e.cancelImmediate = true; - }; - - e.currentTarget = el; - e.relatedTarget = e.fromElement || null; - e.target = e.target || e.srcElement || el; - e.timeStamp = new Date().getTime(); - - if (e.clientX) { - e.pageX = e.clientX + document.documentElement.scrollLeft; - e.pageY = e.clientY + document.documentElement.scrollTop; - } - - while (++i < lg && !e.cancelImmediate) { - if (i in evs) { - eE = evs[i]; - - if (ls.indexOf(eE) !== -1 && typeof eE === 'function') { - eE.call(el, e); - } - } - } - }; - - el._events[t].list = []; - - if (el.attachEvent) { - el.attachEvent('on' + t, el._events[t]); - } - } - - el._events[t].list.push(l); - }; - - window.removeEventListener = Window.prototype.removeEventListener = Document.prototype.removeEventListener = Element.prototype.removeEventListener = function removeEventListener() { - var el = this, t = arguments[0], l = arguments[1], i; // element // type // listener // index - - if (el._events && el._events[t] && el._events[t].list) { - i = el._events[t].list.indexOf(l); - - if (i !== -1) { - el._events[t].list.splice(i, 1); - - if (!el._events[t].list.length) { - if (el.detachEvent) { - el.detachEvent('on' + t, el._events[t]); - } - delete el._events[t]; - } - } - } - }; - })(); -} - -// Event dispatcher / trigger -if (!window.dispatchEvent||!Window.prototype.dispatchEvent||!Document.prototype.dispatchEvent||!Element.prototype.dispatchEvent) { - (function(){ - window.dispatchEvent = Window.prototype.dispatchEvent = Document.prototype.dispatchEvent = Element.prototype.dispatchEvent = function dispatchEvent(e) { - if (!arguments.length) { - throw new Error('Not enough arguments'); - } - - if (!e || typeof e.type !== 'string') { - throw new Error('DOM Events Exception 0'); - } - - var el = this, t = e.type; // element | event type - - try { - if (!e.bubbles) { - e.cancelBubble = true; - - var cancelBubbleEvent = function (event) { - event.cancelBubble = true; - - (el || window).detachEvent('on' + t, cancelBubbleEvent); - }; - - this.attachEvent('on' + t, cancelBubbleEvent); - } - - this.fireEvent('on' + t, e); - } catch (error) { - e.target = el; - - do { - e.currentTarget = el; - - if ('_events' in el && typeof el._events[t] === 'function') { - el._events[t].call(el, e); - } - - if (typeof el['on' + t] === 'function') { - el['on' + t].call(el, e); - } - - el = el.nodeType === 9 ? el.parentWindow : el.parentNode; - } while (el && !e.cancelBubble); - } - - return true; - }; - })(); -} \ No newline at end of file diff --git a/demo/assets/js/perf.js b/demo/assets/js/perf.js deleted file mode 100644 index 4c7723d..0000000 --- a/demo/assets/js/perf.js +++ /dev/null @@ -1,178 +0,0 @@ -//returns browser prefix -function getPrefix() { - var div = document.createElement('div'), i = 0, pf = ['Moz', 'moz', 'Webkit', 'webkit', 'O', 'o', 'Ms', 'ms'], pl = pf.length, - s = ['MozTransform', 'mozTransform', 'WebkitTransform', 'webkitTransform', 'OTransform', 'oTransform', 'MsTransform', 'msTransform']; - - for (i; i < pl; i++) { if (s[i] in div.style) { return pf[i]; } } - div = null; -} - -// generate a random number within a given range -function random(min, max) { - return Math.random() * (max - min) + min; -} - -// vendor prefix handle -var prefix = getPrefix(), // prefix - prefixRequired = (!('transform' in document.getElementsByTagName('div')[0].style)) ? true : false, // is prefix required for transform - transformProperty = prefixRequired ? prefix + 'Transform' : 'transform'; - -// the variables -var container = document.getElementById('container'), - easing = 'easingQuadraticInOut', - tweens = []; - -function createTest(count, property, engine, repeat, hack) { - for (var i = 0; i < count; i++) { - var tween, - div = document.createElement('div'), - windowHeight = document.documentElement.clientHeight - 10, - left = random(-200, 200), - toLeft = random(-200, 200), - top = Math.round(Math.random() * parseInt(windowHeight)), - background = 'rgb('+parseInt(random(0, 255))+','+parseInt(random(0, 255))+','+parseInt(random(0, 255))+')', - fromValues, toValues, fn = i===count-1 ? complete : null; - repeat = parseInt(repeat); - - div.className = 'line'; - div.style.top = top + 'px'; - div.style.backgroundColor = background; - - if (property==='left') { - div.style.left = left + 'px'; - if (hack) { div.className += ' hack'; } - fromValues = engine==="tween" ? { left: left, div: div } : { left: left }; - toValues = { left: toLeft } - } else { - div.style[transformProperty] = 'translate3d('+left + 'px,0px,0px)'; - if (engine==="kute"){ - fromValues = { translateX: left } - toValues = { translateX: toLeft } - } else if ((engine==="gsap") || (engine==="tween")) { - fromValues = engine==='gsap' ? { x: left } : { x: left, div : div } - toValues = { x: toLeft } - } - } - - container.appendChild(div); - - // perf test - if (engine==='kute') { - tween = KUTE.fromTo(div, fromValues, toValues, { delay: 100, easing: easing, repeat: repeat, yoyo: true, duration: 1000, complete: fn }); - tweens.push(tween); - } else if (engine==='gsap') { - if (property==="left"){ - tween = TweenMax.fromTo(div, 1, fromValues, {left : toValues.left, repeat : repeat, yoyo : true, ease : Quad.easeInOut, onComplete: fn }); - } else { - tween = TweenMax.fromTo(div, 1, fromValues, { x:toValues.x, repeat : repeat, yoyo : true, ease : Quad.easeInOut, onComplete: fn }); - } - } else if (engine==='tween') { - var update; - - if (property==="left"){ - update = function(){ - this.div.style['left'] = this.left+'px'; - } - } else if (property==="translateX"){ - update = function(){ - this.div.style[transformProperty] = 'translate3d('+this.x + 'px,0px,0px)'; - } - } - - tween = new TWEEN.Tween(fromValues) - .to(toValues,1000) - .easing( TWEEN.Easing.Quadratic.InOut ) - .onComplete( complete ) - .onUpdate( update) - .repeat(repeat) - .yoyo(true); - tweens.push(tween); - } - } - if (engine==='tween') { - animate(); - function animate( time ) { - requestAnimationFrame( animate ); - TWEEN.update( time ); - } - } - - // since our engines don't do sync, we make it our own here - if (engine==='tween'||engine==='kute') { - var now = window.performance.now(); - for (var t =0; t'; - b.setAttribute('data-'+link.parentNode.parentNode.parentNode.id,link.id); - if ( /LEFT/.test(document.getElementById('property').querySelector('.btn').innerHTML) ) { - document.getElementById('hack').style.display = 'block'; - } else { - document.getElementById('hack').style.display = 'none'; - } - } - } -} - -document.getElementById('hack').querySelector('.btn').onclick = function(){ - var self= this; - setTimeout(function(){ - if ( !self.querySelector('INPUT').checked ) { - self.className = self.className.replace('btn-info','btn-warning'); - self.querySelector('.state').innerHTML = 'Hack ON'; - } else if ( self.querySelector('INPUT').checked ) { - self.className = self.className.replace('btn-warning','btn-info'); - self.querySelector('.state').innerHTML = 'Hack OFF'; - } - },200) -} - -// the start button handle -document.getElementById('start').onclick = function(){ - var c = document.querySelector('[data-count]'), e = document.querySelector('[data-engine]'), r = document.querySelector('[data-repeat]'), - p = document.querySelector('[data-property]'), ct = c && document.querySelector('[data-count]').getAttribute('data-count'), - count = ct ? parseInt(ct) : null, - engine = e && document.querySelector('[data-engine]').getAttribute('data-engine') || null, - repeat = r && document.querySelector('[data-repeat]').getAttribute('data-repeat') || null, - property = p && document.querySelector('[data-property]').getAttribute('data-property') || null, - hack = document.getElementById('hack').getElementsByTagName('INPUT')[0].getAttribute('checked') ? true : false, - warning = document.createElement('DIV'); - - warning.className = 'text-warning padding lead'; - container.innerHTML = ''; - if (count && engine && property && repeat) { - document.getElementById('info').style.display = 'none'; - - createTest(count,property,engine,repeat,hack); - } else { - - if (!count && !property && !repeat && !engine){ - warning.innerHTML = 'We are missing all the settings here.'; - } else { - warning.innerHTML = 'Now missing
'; - warning.innerHTML += !engine ? '- engine
' : ''; - warning.innerHTML += !property ? '- property
' : ''; - warning.innerHTML += !repeat ? '- repeat
' : ''; - warning.innerHTML += !count ? '- count
' : ''; - } - - container.appendChild(warning); - } -} \ No newline at end of file diff --git a/demo/assets/js/prism.js b/demo/assets/js/prism.js deleted file mode 100644 index 8d21c08..0000000 --- a/demo/assets/js/prism.js +++ /dev/null @@ -1,6 +0,0 @@ -/* http://prismjs.com/download.html?themes=prism-okaidia&languages=markup+css+clike+javascript */ -var _self="undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{},Prism=function(){var e=/\blang(?:uage)?-(?!\*)(\w+)\b/i,t=_self.Prism={util:{encode:function(e){return e instanceof n?new n(e.type,t.util.encode(e.content),e.alias):"Array"===t.util.type(e)?e.map(t.util.encode):e.replace(/&/g,"&").replace(/e.length)break e;if(!(d instanceof a)){u.lastIndex=0;var m=u.exec(d);if(m){c&&(f=m[1].length);var y=m.index-1+f,m=m[0].slice(f),v=m.length,k=y+v,b=d.slice(0,y+1),w=d.slice(k+1),P=[p,1];b&&P.push(b);var A=new a(i,g?t.tokenize(m,g):m,h);P.push(A),w&&P.push(w),Array.prototype.splice.apply(r,P)}}}}}return r},hooks:{all:{},add:function(e,n){var a=t.hooks.all;a[e]=a[e]||[],a[e].push(n)},run:function(e,n){var a=t.hooks.all[e];if(a&&a.length)for(var r,l=0;r=a[l++];)r(n)}}},n=t.Token=function(e,t,n){this.type=e,this.content=t,this.alias=n};if(n.stringify=function(e,a,r){if("string"==typeof e)return e;if("Array"===t.util.type(e))return e.map(function(t){return n.stringify(t,a,e)}).join("");var l={type:e.type,content:n.stringify(e.content,a,r),tag:"span",classes:["token",e.type],attributes:{},language:a,parent:r};if("comment"==l.type&&(l.attributes.spellcheck="true"),e.alias){var i="Array"===t.util.type(e.alias)?e.alias:[e.alias];Array.prototype.push.apply(l.classes,i)}t.hooks.run("wrap",l);var o="";for(var s in l.attributes)o+=(o?" ":"")+s+'="'+(l.attributes[s]||"")+'"';return"<"+l.tag+' class="'+l.classes.join(" ")+'" '+o+">"+l.content+""},!_self.document)return _self.addEventListener?(_self.addEventListener("message",function(e){var n=JSON.parse(e.data),a=n.language,r=n.code,l=n.immediateClose;_self.postMessage(t.highlight(r,t.languages[a],a)),l&&_self.close()},!1),_self.Prism):_self.Prism;var a=document.getElementsByTagName("script");return a=a[a.length-1],a&&(t.filename=a.src,document.addEventListener&&!a.hasAttribute("data-manual")&&document.addEventListener("DOMContentLoaded",t.highlightAll)),_self.Prism}();"undefined"!=typeof module&&module.exports&&(module.exports=Prism),"undefined"!=typeof global&&(global.Prism=Prism); -Prism.languages.markup={comment://,prolog:/<\?[\w\W]+?\?>/,doctype://,cdata://i,tag:{pattern:/<\/?[^\s>\/=.]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i,inside:{tag:{pattern:/^<\/?[^\s>\/]+/i,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"attr-value":{pattern:/=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,inside:{punctuation:/[=>"']/}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:/&#?[\da-z]{1,8};/i},Prism.hooks.add("wrap",function(a){"entity"===a.type&&(a.attributes.title=a.content.replace(/&/,"&"))}),Prism.languages.xml=Prism.languages.markup,Prism.languages.html=Prism.languages.markup,Prism.languages.mathml=Prism.languages.markup,Prism.languages.svg=Prism.languages.markup; -Prism.languages.css={comment:/\/\*[\w\W]*?\*\//,atrule:{pattern:/@[\w-]+?.*?(;|(?=\s*\{))/i,inside:{rule:/@[\w-]+/}},url:/url\((?:(["'])(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,selector:/[^\{\}\s][^\{\};]*?(?=\s*\{)/,string:/("|')(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1/,property:/(\b|\B)[\w-]+(?=\s*:)/i,important:/\B!important\b/i,"function":/[-a-z0-9]+(?=\()/i,punctuation:/[(){};:]/},Prism.languages.css.atrule.inside.rest=Prism.util.clone(Prism.languages.css),Prism.languages.markup&&(Prism.languages.insertBefore("markup","tag",{style:{pattern:/()[\w\W]*?(?=<\/style>)/i,lookbehind:!0,inside:Prism.languages.css,alias:"language-css"}}),Prism.languages.insertBefore("inside","attr-value",{"style-attr":{pattern:/\s*style=("|').*?\1/i,inside:{"attr-name":{pattern:/^\s*style/i,inside:Prism.languages.markup.tag.inside},punctuation:/^\s*=\s*['"]|['"]\s*$/,"attr-value":{pattern:/.+/i,inside:Prism.languages.css}},alias:"language-css"}},Prism.languages.markup.tag)); -Prism.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\w\W]*?\*\//,lookbehind:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0}],string:/(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,"class-name":{pattern:/((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,lookbehind:!0,inside:{punctuation:/(\.|\\)/}},keyword:/\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,"boolean":/\b(true|false)\b/,"function":/[a-z0-9_]+(?=\()/i,number:/\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i,operator:/--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,punctuation:/[{}[\];(),.:]/}; -Prism.languages.javascript=Prism.languages.extend("clike",{keyword:/\b(as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)\b/,number:/\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,"function":/[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*(?=\()/i}),Prism.languages.insertBefore("javascript","keyword",{regex:{pattern:/(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,lookbehind:!0}}),Prism.languages.insertBefore("javascript","class-name",{"template-string":{pattern:/`(?:\\`|\\?[^`])*`/,inside:{interpolation:{pattern:/\$\{[^}]+\}/,inside:{"interpolation-punctuation":{pattern:/^\$\{|\}$/,alias:"punctuation"},rest:Prism.languages.javascript}},string:/[\s\S]+/}}}),Prism.languages.markup&&Prism.languages.insertBefore("markup","tag",{script:{pattern:/()[\w\W]*?(?=<\/script>)/i,lookbehind:!0,inside:Prism.languages.javascript,alias:"language-javascript"}}),Prism.languages.js=Prism.languages.javascript; diff --git a/demo/assets/js/scripts.js b/demo/assets/js/scripts.js deleted file mode 100644 index babe497..0000000 --- a/demo/assets/js/scripts.js +++ /dev/null @@ -1,14 +0,0 @@ -// common demo JS - -function getRandomInt(min, max) { - return Math.floor(Math.random() * (max - min + 1)) + min; -} - -//scroll top? -var toTop = document.getElementById('toTop'); -toTop.addEventListener('click',topHandler,false); - -function topHandler(e){ - e.preventDefault(); - KUTE.to( 'window', { scroll: 0 }, {easing: 'easingQuarticOut', duration : 1500 } ).start(); -} \ No newline at end of file diff --git a/demo/assets/js/tween.min.js b/demo/assets/js/tween.min.js deleted file mode 100644 index 9c2a893..0000000 --- a/demo/assets/js/tween.min.js +++ /dev/null @@ -1,2 +0,0 @@ -// tween.js MIT License -!function(){if("performance"in window==!1&&(window.performance={}),Date.now=Date.now||function(){return(new Date).getTime()},"now"in window.performance==!1){var n=window.performance.timing&&window.performance.timing.navigationStart?window.performance.timing.navigationStart:Date.now();window.performance.now=function(){return Date.now()-n}}}();var TWEEN=TWEEN||function(){var n=[];return{getAll:function(){return n},removeAll:function(){n=[]},add:function(t){n.push(t)},remove:function(t){var r=n.indexOf(t);-1!==r&&n.splice(r,1)},update:function(t){if(0===n.length)return!1;var r=0;for(t=void 0!==t?t:window.performance.now();rn;n++)E[n].stop()},this.delay=function(n){return s=n,this},this.repeat=function(n){return e=n,this},this.yoyo=function(n){return a=n,this},this.easing=function(n){return l=n,this},this.interpolation=function(n){return p=n,this},this.chain=function(){return E=arguments,this},this.onStart=function(n){return w=n,this},this.onUpdate=function(n){return M=n,this},this.onComplete=function(n){return v=n,this},this.onStop=function(n){return d=n,this},this.update=function(n){var f,d,m;if(h>n)return!0;I===!1&&(null!==w&&w.call(t),I=!0),d=(n-h)/u,d=d>1?1:d,m=l(d);for(f in i){var g=r[f]||0,T=i[f];T instanceof Array?t[f]=p(T,m):("string"==typeof T&&(T=g+parseFloat(T,10)),"number"==typeof T&&(t[f]=g+(T-g)*m))}if(null!==M&&M.call(t,m),1===d){if(e>0){isFinite(e)&&e--;for(f in o){if("string"==typeof i[f]&&(o[f]=o[f]+parseFloat(i[f],10)),a){var O=o[f];o[f]=i[f],i[f]=O}r[f]=o[f]}return a&&(c=!c),h=n+s,!0}null!==v&&v.call(t);for(var N=0,W=E.length;W>N;N++)E[N].start(h+u);return!1}return!0}},TWEEN.Easing={Linear:{None:function(n){return n}},Quadratic:{In:function(n){return n*n},Out:function(n){return n*(2-n)},InOut:function(n){return(n*=2)<1?.5*n*n:-.5*(--n*(n-2)-1)}},Cubic:{In:function(n){return n*n*n},Out:function(n){return--n*n*n+1},InOut:function(n){return(n*=2)<1?.5*n*n*n:.5*((n-=2)*n*n+2)}},Quartic:{In:function(n){return n*n*n*n},Out:function(n){return 1- --n*n*n*n},InOut:function(n){return(n*=2)<1?.5*n*n*n*n:-.5*((n-=2)*n*n*n-2)}},Quintic:{In:function(n){return n*n*n*n*n},Out:function(n){return--n*n*n*n*n+1},InOut:function(n){return(n*=2)<1?.5*n*n*n*n*n:.5*((n-=2)*n*n*n*n+2)}},Sinusoidal:{In:function(n){return 1-Math.cos(n*Math.PI/2)},Out:function(n){return Math.sin(n*Math.PI/2)},InOut:function(n){return.5*(1-Math.cos(Math.PI*n))}},Exponential:{In:function(n){return 0===n?0:Math.pow(1024,n-1)},Out:function(n){return 1===n?1:1-Math.pow(2,-10*n)},InOut:function(n){return 0===n?0:1===n?1:(n*=2)<1?.5*Math.pow(1024,n-1):.5*(-Math.pow(2,-10*(n-1))+2)}},Circular:{In:function(n){return 1-Math.sqrt(1-n*n)},Out:function(n){return Math.sqrt(1- --n*n)},InOut:function(n){return(n*=2)<1?-.5*(Math.sqrt(1-n*n)-1):.5*(Math.sqrt(1-(n-=2)*n)+1)}},Elastic:{In:function(n){var t,r=.1,i=.4;return 0===n?0:1===n?1:(!r||1>r?(r=1,t=i/4):t=i*Math.asin(1/r)/(2*Math.PI),-(r*Math.pow(2,10*(n-=1))*Math.sin(2*(n-t)*Math.PI/i)))},Out:function(n){var t,r=.1,i=.4;return 0===n?0:1===n?1:(!r||1>r?(r=1,t=i/4):t=i*Math.asin(1/r)/(2*Math.PI),r*Math.pow(2,-10*n)*Math.sin(2*(n-t)*Math.PI/i)+1)},InOut:function(n){var t,r=.1,i=.4;return 0===n?0:1===n?1:(!r||1>r?(r=1,t=i/4):t=i*Math.asin(1/r)/(2*Math.PI),(n*=2)<1?-.5*r*Math.pow(2,10*(n-=1))*Math.sin(2*(n-t)*Math.PI/i):r*Math.pow(2,-10*(n-=1))*Math.sin(2*(n-t)*Math.PI/i)*.5+1)}},Back:{In:function(n){var t=1.70158;return n*n*((t+1)*n-t)},Out:function(n){var t=1.70158;return--n*n*((t+1)*n+t)+1},InOut:function(n){var t=2.5949095;return(n*=2)<1?.5*n*n*((t+1)*n-t):.5*((n-=2)*n*((t+1)*n+t)+2)}},Bounce:{In:function(n){return 1-TWEEN.Easing.Bounce.Out(1-n)},Out:function(n){return 1/2.75>n?7.5625*n*n:2/2.75>n?7.5625*(n-=1.5/2.75)*n+.75:2.5/2.75>n?7.5625*(n-=2.25/2.75)*n+.9375:7.5625*(n-=2.625/2.75)*n+.984375},InOut:function(n){return.5>n?.5*TWEEN.Easing.Bounce.In(2*n):.5*TWEEN.Easing.Bounce.Out(2*n-1)+.5}}},TWEEN.Interpolation={Linear:function(n,t){var r=n.length-1,i=r*t,o=Math.floor(i),u=TWEEN.Interpolation.Utils.Linear;return 0>t?u(n[0],n[1],i):t>1?u(n[r],n[r-1],r-i):u(n[o],n[o+1>r?r:o+1],i-o)},Bezier:function(n,t){for(var r=0,i=n.length-1,o=Math.pow,u=TWEEN.Interpolation.Utils.Bernstein,e=0;i>=e;e++)r+=o(1-t,i-e)*o(t,e)*n[e]*u(i,e);return r},CatmullRom:function(n,t){var r=n.length-1,i=r*t,o=Math.floor(i),u=TWEEN.Interpolation.Utils.CatmullRom;return n[0]===n[r]?(0>t&&(o=Math.floor(i=r*(1+t))),u(n[(o-1+r)%r],n[o],n[(o+1)%r],n[(o+2)%r],i-o)):0>t?n[0]-(u(n[0],n[0],n[1],n[1],-i)-n[0]):t>1?n[r]-(u(n[r],n[r],n[r-1],n[r-1],i-r)-n[r]):u(n[o?o-1:0],n[o],n[o+1>r?r:o+1],n[o+2>r?r:o+2],i-o)},Utils:{Linear:function(n,t,r){return(t-n)*r+n},Bernstein:function(n,t){var r=TWEEN.Interpolation.Utils.Factorial;return r(n)/r(t)/r(n-t)},Factorial:function(){var n=[1];return function(t){var r=1;if(n[t])return n[t];for(var i=t;i>1;i--)r*=i;return n[t]=r,r}}(),CatmullRom:function(n,t,r,i,o){var u=.5*(r-n),e=.5*(i-t),a=o*o,f=o*a;return(2*t-2*r+u+e)*f+(-3*t+3*r-2*u-e)*a+u*o+t}}},function(n){"function"==typeof define&&define.amd?define([],function(){return TWEEN}):"object"==typeof exports?module.exports=TWEEN:n.TWEEN=TWEEN}(this); \ No newline at end of file diff --git a/demo/examples.html b/demo/examples.html deleted file mode 100644 index 8e2400e..0000000 --- a/demo/examples.html +++ /dev/null @@ -1,499 +0,0 @@ - - - - - - - - - - - - - - - - - KUTE.js Examples | Javascript Animation Engine - - - - - - - - - - - - - - - - - - -
- -
- - - -
-

Quick Examples

-

KUTE.js can be used in most cases with native Javascript, but also with jQuery. So, before we head over to the more advanced examples, let's have a quick look at these two basic examples here. Note: the examples are posted on codepen.

- -

Basic Native Javascript Example

-

When developing with native Javascript, a very basic syntax goes like this:

- -
-// this is the tween object, basically KUTE.method(element, from, to, options);
-var tween = KUTE.fromTo('selector', {left: 0}, {left: 100}, {yoyo: true});
-
- -

Now the tween object is created, it's a good time for you to know that via Native Javascript we always animate the first HTML element only, even if you're using a class selector. To create/control a tween for multiple elements such as querySelectorAll() or getElementsByTagName(), you need to do a for () loop. Now let's apply the tween control methods:

-
tween.start(); // starts the animation
-tween.stop(); // stops current tween and all chained tweens animating
-tween.pause(); // pauses current tween animation
-tween.play(); // or tween.resume(); resumes current tween animation
-tween.chain(tween2); // when tween animation finished, you can trigger the start of another tween
-
-

The demo for the above example is here.

- -

Basic jQuery Example

-

KUTE.js includes a jQuery plugin to help you easily implement KUTE.js in your jQuery applications. When using jQuery, the syntax is familiar but works a bit different than plain Javascript due to jQuery's specific code standards. Let's have a look:

-
// this is the tween object, basically $('selector').KUTE(method, from, to, options);
-var tween = $('selector').KUTE('fromTo', {top: 20}, {top: 100}, {yoyo: true});
-
-

We mentioned that the KUTE jQuery plugin is different, and here's why: the above code creates an Array of objects for each HTML element of chosen selector, while the Native Javascript creates a single object. For these objects we can now apply the tween control methods as follows:

-
$(tween).KUTE('start'); // starts the animation
-$(tween).KUTE('stop'); // stops current tween and all chained tweens animating
-$(tween).KUTE('pause'); // pauses current tween animation
-$(tween).KUTE('play'); // or $(myTween).KUTE('resume'); resumes current tween animation
-$(tween).KUTE('chain',myTween2); // when tween animation finished, you can trigger the start of another tween
-
-

The demo for the above example is here.

- -

Transform Properties Examples

-

KUTE.js supports almost all about transform as described in the spec: the 2D translate, rotate, skewX, skewY and scale, as well as the 3D translateX, translateY, translateZ, translate3d, rotateX, rotateX, rotateY, rotateZ properties. Additionally it allows you to set a perspective for the element or it's parent as well as a perpective-origin for the element or it's parent.

- -

Translations

-

In the next example the first box is moving to left 250px with translate property, the second box is moving to the right by 200px using translateX and the third box is moving to the bottom using translate3d. The last box also uses translate3d but requires a perspective value for the animation on the Z axis to be effective.

-
var tween1 = KUTE.fromTo('selector1',{translate:0},{translate:-250}); // or translate:[x,y] for both axis
-var tween2 = KUTE.fromTo('selector2',{translateX:0},{translateX:200});
-var tween3 = KUTE.fromTo('selector3',{translate3d:[0,0,0]},{translate3d:[0,100,0]});
-var tween4 = KUTE.fromTo('selector4',{translate3d:[0,0,0]},{translate3d:[0,0,-100]},{parentPerspective: 100});
-
-

And here is how it looks like:

-
-
2D
-
X
-
Y
-
Z
- -
- Start -
-
- -

As you can see in your browsers console, for all animations translate3d is used, as explained in the features page. Also the first example that's using the 2D translate for both vertical and horizontal axis even if we only set X axis. You can download this example here.

-

Remember: stacking translate and translate3d together may not work and IE9 does not support perspective.

- -

Rotations

-

Next we're gonna animate 4 elements with one axis each element. Unlike translations, KUTE.js does not support rotate3d.

-
var tween1 = KUTE.fromTo('selector1',{rotate:0},{rotate:-720});
-var tween2 = KUTE.fromTo('selector2',{rotateX:0},{rotateX:200});
-var tween3 = KUTE.fromTo('selector3',{rotateY:0},{rotateY:160},{perspective:100});
-var tween4 = KUTE.fromTo('selector4',{rotateZ:0},{rotateZ:360});
-
-

And here is how it looks like:

-
-
2D
-
X
-
Y
-
Z
- -
- Start -
-
-

The rotateX and rotateY are 3D based rotations, so they require a perspective in order to make the browser render proper 3D layers, but in the example they animate different because only the second, Y axis, uses a perspective setting. The rotation on Z axis does not require a perspective. Unlike translations, you can stack all axis rotation for your animation, but we will see that in a later example. You can download this example here.

- -

Skews

-

KUTE.js supports skewX and skewY so let's animate the two. Since they are 2D transformations, IE9 supports skews.

-
var tween1 = KUTE.fromTo('selector1',{skewX:0},{skewX:20});
-var tween2 = KUTE.fromTo('selector2',{skewY:0},{skewY:45});
-
- -

And here is how it looks like:

-
-
X
-
Y
- -
- Start -
-
-

You can download this example here.

- -

Mixed Transformations

-

The current specification does not support animating different transform properties with multiple tween objects at the same time, you must stack them all together into a single object. See the example below:

- -
var tween1 = KUTE.fromTo('selector1',{rotateX:0},{rotateX:20}).start();
-var tween2 = KUTE.fromTo('selector1',{skewY:0},{skewY:45}).start();
-
-

If you check the test here, you will notice that only the skewY is going to work and no rotation. Now let's do this properly.

- -
var tween1 = KUTE.fromTo(
-	'selector1', // element
-	{translateX:0, rotateX:0, rotateY:0, rotateZ:0}, // from
-	{translateX:250, rotateX:360, rotateY:15, rotateZ:5}, // to
-	{perspective:400, perspectiveOrigin: 'center top'} // trasform options
-);
-var tween2 = KUTE.fromTo(
-	'selector2', // element
-	{translateX:0, rotateX:0, rotateY:0, rotateZ:0}, // from values
-	{translateX:-250, rotateX:360, rotateY:15, rotateZ:5}, // to values
-	{parentPerspective:400, parentPerspectiveOrigin: 'center top'} // trasform options
-);
-
-

Now you can see we are using the specific transform options, the first tween object uses these settings for an element and the second for its parent.

- -
-
element perspective 400px
-
parent perspective 400px
- -
- Start -
-
- -

This example also shows the difference between an element's perspective and a parent's perspective. You can download the above example here.

- -

Chained Transformations

-

I'm gonna insist on the tween chaining feature a bit because when we run animations one after another we are kinda expecting a certain degree of continuity. As explained before, the best solution is the .to() method because it has the ability to stack properties found in the element's inline styling, mostly from previous tween animation, and use them as start values for the next tween. It also transfers unchanged values to values end for that same reason. OK now, let's see a side by side comparison with 3 elements:

-
-
FROMTO
-
FROMTO
-
TO
- -
- Start -
-
-

What's this all about?

-
    -
  • the first box uses a regular .fromTo() object, we are doing things normally, we would expect them to work properly but due to the nature of the transforms, this is what it does
  • -
  • the second box is also using .fromTo() object, but using proper values for all tweens at all times, so we fixed that glitch
  • -
  • and the last box uses the .to() method, and does the chaining easier for most properties, especially for transform
  • -
- -

When coding transformation chains I would highly recommend:

-
    -
  • keep the same order of the transform properties, best would be: translation, rotation, skew and scale; an example of the difference shown here for rotations and here for rotations and skew;
  • -
  • 2D and 3D translations would work best in if you provide a value at all times; eg. translate:[x,y] and translate3d:[x,y,z]; for instance using translate:150 or translateX:150 would mean that all other axis are 0;
  • -
  • on larger amount of elements animating chains, the .fromTo() method is fastest, so you will have more work, but can potentially minimize or eliminate any syncronization issues that may occur, as explained in the features page;
  • -
  • download this example here.
  • -
- -

Border Radius

-

In the example below we are doing some animation on the border-radius property. The first box animates all corners, while the other boxes animate each corner at a time. A quick reminder, for radius properties KUTE.js supports px, % and text properties' units such as em or rem.

-
KUTE.to('selector1',{borderRadius:'100%'}).start();
-KUTE.to('selector2',{borderTopLeftRadius:'100%'}).start();
-KUTE.to('selector3',{borderTopRightRadius:'100%'}).start();
-KUTE.to('selector4',{borderBottomLeftRadius:'100%'}).start();
-KUTE.to('selector5',{borderBottomRightRadius:'100%'}).start();
-
- -

And here is how it looks like:

- -
-
ALL
-
TL
-
TR
-
BL
-
BR
- -
- Start -
-
- -

A quick important reminder here is that KUTE.js does not support shorthands for radius properties. Also early implementations by Mozilla's Firefox browser like -moz-border-radius-topleft are not supported because they were depracated with later versions. Download this example here.

- -

Box Model Properties

-

While KUTE.js supports almost all the box model properties, the next example will animate most common properties, we will focus mostly on size, spacing and position. Other properties such as minWidth or maxHeight require a more complex context and we won't insist on them.

-
var tween1 = KUTE.to('selector1',{width:200});
-var tween2 = KUTE.to('selector1',{height:300});
-var tween3 = KUTE.to('selector1',{left:250});
-var tween4 = KUTE.to('selector1',{top:100});
-var tween5 = KUTE.to('selector1',{padding:'5%'});
-
-

We're gonna chain these tweens and start the animation. You can download this example here.

-
-
BOX MODEL
- -
- Start -
-
- - -

TIP: the width and height properties used together can be great for scale animation fallback on images for legacy browsers.

- -

Text Properties

-

OK here we're gonna do a cool example for text properties. Basically the below code would work:

-
var tween1 = KUTE.to('selector1',{fontSize:'200%'});
-var tween2 = KUTE.to('selector1',{line-height:24});
-var tween3 = KUTE.to('selector1',{letter-spacing:50});
-
-

But our example will feature some more than just that. We're gonna animate each character of a given string, with a small delay. The heading will animate fontSize and letterSpacing properties for each character while the button will animate fontSize and lineHeight properties. Watch this:

- -
-

Howdy!

- Button - -
- Start -
-
-

TIP: this should also work in IE8 as a fallback for scale animation for text. It's not perfect, can be improved for sure, but if it's a must, this would do. Download this example here.

- -

Color Properties

-

The next example is about animating color properties. As for example, check these lines for reference.

-
KUTE.to('selector1',{color:'#069'}).start();
-KUTE.to('selector1',{backgroundColor:'#069'}).start();
-KUTE.to('selector1',{borderColor:'rgb(25,25,25)'}).start();
-KUTE.to('selector1',{borderTopColor:'#069'}).start();
-KUTE.to('selector1',{borderRightColor:'rgba(25,25,25,0.25)'}).start();
-KUTE.to('selector1',{borderBottomColor:'#069'}).start();
-KUTE.to('selector1',{borderLeftColor:'#069'}).start();
-
-

Let's get some animation going. Download the example here.

- -
-
Colors
- -
- Start -
-
- -

A quick reminder: you can also use RGB or RGBA, but the last one is not supported on IE8 and it will fallback to RGB.

- -

Clip Property

-

This property allows you to animate the rectangular shape of an element that is set to position:absolute. In CSS this property works like this clip: rect(top,right,bottom,left) forming a rectangular shape that masks an element making parts of it invisible.

-
KUTE.to('selector',{clip:[0,150,100,0]}).start();
-

A quick example here could look like this:

- -
-
- -
- Start -
-
-

Note that this would produce no effect for elements that have overflow:visible style rule. Download this example here.

- -

Background Position

-

Another property we can animate with KUTE.js is backgroundPosition. Quick example:

-
KUTE.to('selector1',{backgroundPosition:[0,50]}).start();
-

A working example would look like this:

- -
-
- -
- Start -
-
-

Download this example here.

- -

Vertical Scrolling

-

Another property we can animate with KUTE.js is scrollTop. I works for both the window and any scrollable object. Quick example:

-
KUTE.to('selector',{scroll:450}).start(); // for a scrollable element
-KUTE.to('window',{scroll:450}).start(); // for the window
-
-

A working example would work like this. Scroll works with IE8+ and is a unitless property even if these scroll distances are measured in pixels.

- - -

Cross Browser Animation Example

-

Unlike the examples hosted on Codepen, most examples here should be supported on legacy browsers. The next example is going to explain more details about how to target browsers according to their supported properties, so stick around. So, if your target audience uses legacy browsers in a significant percent, check to have the proper polyfills and also make sure you target your browsers, here's a complete reference. Now we are ready: - -

Collect Information And Cache It

-
// grab an HTML element to build a tween object for it 
-var element = document.getElementById("myElement");
-
-// check for IE legacy browsers
-var isIE = (new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})").exec(navigator.userAgent) != null) ? parseFloat( RegExp.$1 ) : false;
-var isIE8 = isIE === 8;
-var isIE9 = isIE === 9;
-
-
-// most browsers have specific checks, so make sure 
-// you include all you need for your target audience
-
-
-

Define Properties And Options Objects

-
// create values and options objects
-var startValues = {};
-var endValues = {};
-var options = {};
-
-// here we define properties that are commonly supported
-startValues.opacity = 1;
-endValues.opacity = 0.2;
-startValues.backgroundColor = '#CDDC39'; 
-endValues.backgroundColor = '#ec1e71';
-
-// here we define the properties according to the target browsers
-if (isIE8) { // or any other browser that doesn"t support transforms		
-	startValues.left = 0;
-	endValues.left = 250;
-} else if (isIE9) { // or any other browser that only support 2d transforms
-	startValues.translate = 0; // 2d translate on X axis
-	endValues.translate = 250;
-	startValues.rotate = -180; // 2d rotation on Z axis
-	endValues.rotate = 0;
-	startValues.scale = 1; // 2d scale
-	endValues.scale = 1.5;
-} else { // most modern browsers
-	startValues.translate3d = [0,0,0]; //3d translation on X axis
-	endValues.translate3d = [250,0,0];				
-	startValues.rotateZ = -180; // 3d rotation on Z axis
-	endValues.rotateZ = 0;
-	startValues.rotateX = -20; // 3d rotation on X axis
-	endValues.rotateX = 0;				
-	startValues.scale = 1; // 2d scale
-	endValues.scale = 1.5;
-	options.perspective = 400; // 3d transform option
-}
-
-// common tween options
-options.easing = "easingCubicOut";
-options.duration = 2500;
-options.yoyo = true;
-options.repeat = 1;
-
- -

Build Tween Object And Tween Controls

-
// the cached object
-var myTween = KUTE.fromTo(element, startValues, endValues, options);
-
-// trigger buttons
-var startButton = document.getElementById('startButton'),
-	stopButton = document.getElementById('stopButton'),
-	playPauseButton = document.getElementById('playPauseButton');
-
-// add handlers for the trigger buttons
-startButton.addEventListener('click', function(e){
-	e.preventDefault();
-	if (!myTween.playing) { myTween.start(); } // only start the animation if hasn't started yet
-}, false);
-stopButton.addEventListener('click', function(e){
-	e.preventDefault();
-	if (myTween.playing) { myTween.stop(); } // only stop the animation if there is any
-}, false);
-playPauseButton.addEventListener('click', function(e){
-	e.preventDefault();	
-	if (!myTween.paused && myTween.playing) { 
-		myTween.pause(); playPauseButton.innerHTML = 'Resume';
-	} else { 
-		myTween.resume(); 
-		playPauseButton.innerHTML = 'Pause';
-	}  
-}, false);
-
-

Live Demo

-
-
- -
-
- Pause - Start - Stop -
-
-

Let's explain this code a bit. KUTE.js gives you the internal variables myTween.playing and myTween.paused (both true/false) to help you easily manage the tween control methods all together as in this example here. As said before, KUTE.js version 0.9.5 doesn't stat animating by default, for all the examples on this page you have to start it yourself, unlike their versions hosted on Codepen.

-
    -
  • the START button will use the .start() method and the animation starts;
  • -
  • the STOP button will use the .stop() method and stops the animation; after this the, animation can only be started again
  • -
  • the PAUSE button will use the .pause() method and pauses the animation; this also changes the button's text and functionality;
  • -
  • the RESUME button will use the .resume() method and resumes the animation; this reverses the button's initial state;
  • -
  • make sure you work with the conditions properly when you want to pause an animation you MUST check both !myTween.playing and myTween.paused conditions because you could end up with errors.
  • -
- -

Tween Object Collections

-

With KUTE.js 1.0.1 we introduced new tween object constructor methods, they allow you to create a tween object for each element in a collection, a very handy way to ease and speed up the animation programing workflow. Let's have a little fun.

-
// a simple .to() for a collection of elements would look like this
-var myMultiTween1 = KUTE.allTo('selector1',{translate:[0,150]});
-
-// or a more complex .fromTo() example with the two new options
-var myMultiTween2 = KUTE.allFromTo(
-    'selector2',
-    {translate:[0,0], rotate: 0}, 
-    {translate:[0,150], rotate: 360}, 
-    {transformOrigin: '10% 10%', offset: 200 }
-);
-
-
-

And should looks like this:

-
-
K
-
U
-
T
-
E
- -
- Start -
-
-

As you can see, we also used the new tween options offset and transformOrigin and they make it so much more easy.

- -
- - - - -
- - - - - - - - - - - - - - - \ No newline at end of file diff --git a/demo/features.html b/demo/features.html deleted file mode 100644 index 5234724..0000000 --- a/demo/features.html +++ /dev/null @@ -1,223 +0,0 @@ - - - - - - - - - - - - - - - - - KUTE.js Features | Javascript Animation Engine - - - - - - - - - - - - - - - - -
- -
- - - -
-

Badass Performance

-

KUTE.js was developed with best practices in mind for fastest code execution and memory efficiency, but performance varies from case to case, as well as for all the other Javascript based animation engines. As a quick note on how it works, well for the most part values are cached for the entire duration of the animation so that the repetitive tasks run smoothly, uninterruptible and avoid layout thrashing. We all know the more properties used or the more elements to animate at the same time, the more power is required.

- -

Of course some would argue on many aspects, but we all trade something for the sake of something else, such as convenience and/or flexibility or fork a project that's already great to make it.. better. For the sake of performance or simply willing to provide a feature, some trade/neglect other elements such as syncronisation (check this video), code simplicity (lots of CSS for a custom animation) and more other.

-

To learn more about how performance can vary from case to case, check out this secion, it's very informative.

-
- -
-

Browser Prefixes Free

-

KUTE.js uses a simple function to determine the vendor prefix and checks if the prefix is required. In any case it caches the prefixed/unprefixed property name in a variable to make it available when needed. This applies to the following CSS3 properties: transform, perspective, perspective-origin, border-radius and the requestAnimationFrame Javascript method.

-

We aren't only targeting properly browsers for CSS3 styling, but also increase performance because we don't need to update the styling on every frame for all browsers (and their versions) at once, just the right and only one; less string concatenation = more performance. This asumes you are NOT styling the above CSS3 properties using your stylesheets to avoid glitches with legacy browsers.

-

This feature is useful mostly for Safari, older Firefox and Opera versions and Internet Explorer 9.

-
- -
-

Browser Compatibility

-

KUTE.js covers all modern browsers but also provides fallback options for legacy browsers. The prefix free feature mentioned above is one way to enable smooth Javascript based animations on older versions Gecko/Webkit/IE browsers for transform and border-radius. Generally, KUTE.js is built around most used properties, so I highly recommend checking the can I use website for a very detailed properties support list on many browsers and versions. For instance legacy browsers may support 2D transforms or 3D transforms so make sure you know what browsers support and how to target them before you get to work with a complete browser supported animation setup.

-

I've put a lot of work in making KUTE.js work with all Internet Explorer versions starting with IE8 and it really works with the help of polyfills and the appropriate code to detect them. All you need to do is to let the browser breathe, espectially IE8 needs to have resize handlers as minimal as possible. On the other side, IE9 really shines with 2D transforms animation, something that's impossible with CSS transition.

-

Speaking of polyfills, KUTE.js requires window.requestAnimationFrame() for the main thread, window.performance.now() for checking the current time, .indexOf() for array checks, window.getComputedStyle() for the .to() method and .addEventListener() for scroll. Unlike other developers I didn't include these polyfills in the code to keep it clean, so that YOU decide whether your project need them or not. Also know that when using the recommended polyfill service some browser detection will not work because they fill the gap and your code won't work as expected. For instance this would check for IE8 browser var isIE = document.all && !document.addEventListener; but the polyfill covers .addEventListener() so you will never succeed. The provided ideal HTML template is the best solution for targeting Microsoft's legacy browsers.

-

As of Safari, we did some tests there too, KUTE.js does it really well.

-
- -
-

Methods, Tools and Options

-

Building Tween Objects

-

KUTE.js allows you to create tween objects with the help of .to() and .fromTo() public methods for a single element, with distinctive functionalities, and the other .allTo() and .allFromTo() that use the first two for collections of elements.

- -

KUTE.to('selector', toValues, options) method is super simple and straightforward and requires a polyfill for window.getComputedStyle() Javascript method on IE8 and more other legacy browsers in order to read the current property value. If no value is set in the stylesheets or inline style, a property specific value will be used. It also computes the value on animation start, delaying the actual animation and potentially creating sync issues on large amounts of elements, but it has the great ability to stack transform properties as they come in chained tweens. However fixing the sync issues is not that hard, see the example at start() method API.

- -

KUTE.fromTo('selector', fromValues, toValues, options) is the other method that's most powerful in terms of performance, flexibility and control on the animation. As an example, while the first method may not process properties' measurement units properly, this method will never fail in that regard, because you can set for both starting values and end values the exact values with the right unit you need.

- -

It doesn't stack transform properties for chained tweens but you can set all properties to be used in all tweens if you want (end values from previous tween become start values for the next AND unchanged start values become end values), and make sure nothing is left unchecked, to avoid animation glitches. Still, this method is the fastest and bestest for super performance and super control.

- -

KUTE.allTo('selector', toValues, options) inherits all functionality from the .to() method but is applied to collections of elements.

- -

KUTE.allFromTo('selector', fromValues, toValues, options) is the same as .fromTo() and is applied to collections of elements.

- -

Tween Control

-

Unlike previous versions where animations started right away, starting with version 0.9.5 KUTE.js gives you great animation control methods such as: .start(), .stop(), .pause() and .resume(). These public methods work either when animation is running or is paused. You need to see the documentation to learn how these work.

- -

Tween Options

-

Aside from the usual options such as duration, delay, easing, repeat or yoyo, it also comes with specific tween options for transform. For instance 3D rotations require a perspective or a perspective-origin, right?

- -

Callback System

-

Another important KUTE.js feature is the solid callback system. This allows you to schedule functions to run on animation start, on each frame, on pause / resume, on stop and on complete. The functions bound at start or resume will delay the animation, while the functions running on each frame can potentially influence performance on large amounts of elements so you must use them wisely.

- -

Addons

-

KUTE.js sports some fine tuned addons: jQuery Plugin, cubic bezier easing functions and also physics based easing functions. I am also considering to feature an attributes plugin as well as SVG library and maybe other tools in the future.

- -

Check the documentation on these methods and the examples page for more.

-
- -
-

Support For Plenty Of Properties

-

KUTE.js covers all animation needs such as most transform properties, scroll for window or a given element, colors, border-radius, and almost the full box model. Due to it's modular coding, KUTE.js is very flexible and makes it very easy to add support for more properties, but I'm considering removing unnecessary properties in the future (mostly from the box model category). Note: not all browsers support 2D transforms or 3D transforms.

-

All common measurement units are supported: px and % for translations and box-model properties, or deg and rad for rotations and skews, while clip only supports px. Other properties such as opacity, scale or scroll are unitless, and background-position always uses % as measurement unit. As for the text properties you can use px, em, rem, vh and vw. Be sure to check what your browsers support in terms of measurement unit.

- -

Opacity

-

In most cases, the best animation possible is the opacity, for performance, aesthetics and maybe more other reasons such as avoiding unwanted layout changes. KUTE.js also covers IE8 here with the help of proprietary synthax filter: alpha(opacity=0) but requires that you use the provided HTML template in order to detect the browser. Also, opacity can be used for instance on legacy browsers that don't support RGBA colors. Eg. opacity:0.5 will make an element semitransparent.

- -

2D Transform Properties

-
    -
  • translate property can be used for horizontal and / or vertical movement. EG. translate:150 to translate an element 150px to the right or translate:[-150,200] to move the element to the left by 150px and to bottom by 200px. Supported on IE9.
  • -
  • rotate is a property used to rotate an element on the Z axis or the plain document. Eg. rotate:250 will rotate an element clockwise by 250 degrees. Supported on IE9.
  • -
  • skewX is a property used to apply a skew transformation on the X axis. Eg. skewX:25 will skew an element by 25 degrees. Supported on IE9.
  • -
  • skewY is a property used to apply a skew transformation on the Y axis. Eg. skewY:25 will skew an element by 25 degrees. Supported on IE9.
  • -
  • scale is a property used to apply a size transformation. Eg. scale:2 will enlarge an element by a degree of 2. Supported on IE9.
  • -
  • matrix property is not supported.
  • -
- -

3D Transform Properties

-
    -
  • translateX property is for horizontal movement. EG. translateX:150 to translate an element 150px to the right. Modern browsers only.
  • -
  • translateY property is for vertical movement. EG. translateY:-250 to translate an element 250px towards the top. Modern browsers only.
  • -
  • translateZ property is for movement on the Z axis in a given 3D field. EG. translateZ:-250 to translate an element 250px to it's back, making it smaller. Modern browsers only and requires a perspective tween option to be used; the smaller perspective value, the deeper translation.
  • -
  • translate3d property is for movement on all the axis in a given 3D field. EG. translate3d:[-150,200,150] to translate an element 150px to the left, 200px to the bottom and 150px closer to the viewer, making it larger. Modern browsers only and also requires using a perspective tween option.
  • -
  • rotateX property rotates an element on the X axis in a given 3D field. Eg. rotateX:250 will rotate an element clockwise by 250 degrees. Modern browsers only and requires perspective.
  • -
  • rotateY property rotates an element on the Y axis in a given 3D field. Eg. rotateY:-150 will rotate an element counter-clockwise by 150 degrees. Modern browsers only and also requires perspective.
  • -
  • rotateZ property rotates an element on the Z axis and is the equivalent of the 2D rotation. Eg. rotateZ:-150 will rotate an element counter-clockwise by 150 degrees. Modern browsers only and doesn't require perspective.
  • -
  • rotate3d and matrix3d properties are not supported.
  • -
- -

Box Model Properties

-
    -
  • left, top, right and bottom are position based properties for movement on vertical and / or horizontal axis. These properties require that the element to animate uses position: absolute/relative styling as well as it's parent element requires position:relative. These properties can be used as fallback for browsers with no support for translate properties such as IE8.
  • -
  • width, height, minWidth, minHeight, maxWidth, maxHeight are properties that allow you to animate the size of an element on horizontal and / or vertical axis. These properties can be used on images as fallback for scale on IE8 again, as well as for other purposes.
  • -
  • padding, margin, paddingTop, paddingBottom, paddingLeft, paddingRight, marginTop, marginBottom, marginLeft and marginRight are properties that allow you to animate the spacing of an element inside (via padding) and outside (via margin). Shorthand notations such as margin: "20px 50px" or any other type are not supported.
  • -
  • borderWidth, borderTopWidth, borderRightWidth, borderBottomWidth are borderLeftWidth are properties that allow you to animate the border of an element either on all sides at once or each side separatelly. Shorthand notations are not supported.
  • -
-

Remember: these properties are layout modifiers that may force repaint of the entire DOM, drastically affecting performance on lower end and mobile devices. They also trigger resize event that may cause crashes on old browsers such as IE8 when using handlers bound on resize, so use with caution.

- -

Border Radius

-
    -
  • borderRadius allows you to animate the border-radius on all corners for a given element.
  • -
  • borderTopLeftRadius allows you to animate the border-top-left-radius for a given element.
  • -
  • borderTopRightRadius allows you to animate the border-top-right-radius for a given element.
  • -
  • borderBottomLeftRadius allows you to animate the border-bottom-left-radiusfor a given element.
  • -
  • borderBottomRightRadius allows you to animate the border-bottom-right-radiusfor a given element.
  • -
-

For all radius properties above borderRadius:20 or borderTopLeftRadius:'25%' will do. In the first case px is the default measurement unit used, while in the second we require using % unit which is relative to the element's size.

-

Remember: shorthands for border-radius are not supported. Also KUTE.js does not cover early implementations by Mozilla Firefox (Eg. -moz-border-radius-topleft) as they were deprecated with later versions.

- -

Color Properties

-

KUTE.js currently supports values such as HEX, RGB and RGBA for all color properties, but IE8 does not support RGBA and always uses RGB when detected, otherwise will produce no effect. There is also a tween option keepHex:true to convert the color format. Eg. color: '#ff0000' or backgroundColor: 'rgb(202,150,20)' or borderColor: 'rgba(250,100,20,0.5)'

-
    -
  • color allows you to animate the color for a given text element.
  • -
  • backgroundColor allows you to animate the background-color for a given element.
  • -
  • borderColor allows you to animate the border-color on all sides for a given element.
  • -
  • borderTopColor, borderRightColor, borderBottomColor and borderLeftColor properties allow you to animate the color of the border on each side of a given element.
  • -
-

Remember: shorthands for border-color property as well as web color names (Eg. red, green, olive, etc.) are not supported.

- -

Text Properties

-

These properties can be combinated with each other when applied to text elements (paragraphs, headings) as animation fallback for scale on browsers that don't support transform at all. Yes, IE8 and other legacy browsers.

-
    -
  • fontSize allows you to animate the font-size for a given element.
  • -
  • lineHeight allows you to animate the line-height for a given element.
  • -
  • letterSpacing allows you to animate the letter-spacing for a given element.
  • -
-

Remember: these properties are also layout modifiers.

- -

Scroll Animation

-

KUTE.js currently supports only vertical scroll for both the window and a given element that's scrollable. Both scroll: 150 or scrollTop: 150 notations will do. When animating scroll, KUTE.js will disable all scroll and swipe handlers to prevent animation bubbles.

- -

Other properties

-
    -
  • clip allows you to animate the clip property for a given element. Only rect is supported. Eg. clip:[250,200,300,0]. See spec for details.
  • -
  • backgroundPosition allows you to animate the background-position for a given element that uses a background image. It only uses % as measurement unit. Eg. backgroundPosition:[50,20]
  • -
- -

Did We Miss Any Important Property?

-

Make sure you go to the issues tracker and report the missing property ASAP.

-
- -
-

Developer Friendly

-

You can develop with KUTE.js for free thanks to the MIT License terms. The terms in short allow you to use the script for free in both personal and commercial application as long as you give proper credits to the original author. Also a link back would be appreciated.

-

Also KUTE.js is super documented, all features and options are showcased with detailed examples so you can get your hands really dirty.

- - -
- - - - -
- - - - - - - - - - - - diff --git a/demo/index.html b/demo/index.html deleted file mode 100644 index 7bace66..0000000 --- a/demo/index.html +++ /dev/null @@ -1,189 +0,0 @@ - - - - - - - - - - - - - - - - - KUTE.js | Javascript Animation Engine - - - - - - - - - - - - - - - - -
- -
- - - - -
-
-
-
-

Welcome Developers!

-

KUTE.js is a Javascript animation engine with top performance, memory efficient & modular code. It delivers a whole bunch of tools to help you create great custom animations.

-

- Download - Github - CDN - Replay -

-
-
-
-
-
-
-
-
- -
-
-
- -
-
-
- -
-
- -
-
-
- -
-
-

At A Glance

-
-
-

Killer Performance

-

KUTE.js is crazy fast with it's outstanding performance, with super fast code execution, it's also memory efficient. I made a cool demo to showcase how KUTE.js really scales on performance.

-
-
-

Prefix Free

-

KUTE.js can detect if the user's browser requires prefix and uses it accordingly for requestAnimationFrame, transform and border-radius, hustle free for older Gecko/Webkit/IE browsers.

-
-
-
-
-

All Browsers Compatible

-

KUTE.js covers all modern browsers with fallback options for legacy browsers. When using polyfills and the right browser detection you can manage all kinds of fallback animations for legacy browsers.

-
-
-

Powerful Methods

-

KUTE.js allows you to create tweens and chainable tweens, gives you tween control methods (stop/pause/resume/restart) and comes with full spectrum tween options.

-
-
-
-
-

Packed With Tools

-

KUTE.js comes with tools to help you configure awesome animations: jQuery plugin, cubic-bezier and physics easing functions, color convertors, and a lot of options to play with.

-
-
-

Plenty Of Properties

-

KUTE.js covers all animation needs such as transform, scroll (window or other elements), colors (border, background and text), border-radius, almost the full box model and also text properties.

-
-
-
-
-

MIT License

-

You can develop with KUTE.js for free thanks to the MIT License terms.

-
-
-

Top Notch Documentation

-

All examples, code, tips & tricks are very well documented.

-
-
-
-
- -
-

Getting Started

-
-
- -

Examples

-

See KUTE.js in action with all it's functions, options and features.

-
-
- -

Documentation

-

The API documentation is here for you to get you started.

-
- -
- -

Performance

-

Head over to the performance test page right away.

-
-
- - - -
- - - - -
- - - - - - - - - - - - - diff --git a/demo/performance.html b/demo/performance.html deleted file mode 100644 index af3238a..0000000 --- a/demo/performance.html +++ /dev/null @@ -1,139 +0,0 @@ - - - - - - - - - - - - - KUTE.js | Performance Testing Page - - - - - - - -
-

Back to KUTE.js

-

Engine

- - - - - -

Property

- - - - - - -

Repeat

- - - - - - -

How many elements to animate:

- - - - - - - - -
- -
- -
- - - -

These tests are only for modern browsers. In Google Chrome you can enable the FPS metter in developer tools, here's how.

-

The hack refers to adding a blank transform translate3d(0px,0px,0px); for the elements to promote them into separate layers, as described here.

-

Do not try this test on lower end or mobile devices.

- - -
-
- - - - - - - - - - - - - - - - - - diff --git a/demo/src/kute-bezier.js b/demo/src/kute-bezier.js deleted file mode 100644 index f402215..0000000 --- a/demo/src/kute-bezier.js +++ /dev/null @@ -1,198 +0,0 @@ -/* - * KUTE.js - The Light Tweening Engine | dnp_theme - * package bezier easing - * BezierEasing by Gaëtan Renaudeau 2014 – MIT License - * optimized by dnp_theme 2015 – MIT License - * Licensed under MIT-License -*/ - -// /* THIS IS THE OLD CODE */ -// (function(kute_ea){ -// // Obtain a reference to the base KUTE. -// // Since KUTE supports a variety of module systems, -// // we need to pick up which one to use. -// if(define == "function") { -// define(["./kute.js"], function(KUTE){ kute_ea(KUTE); return KUTE; }); -// } else if(typeof module == "object" && typeof require == "function") { -// // We assume, that require() is sync. -// var KUTE = require("./kute.js"); -// kute_ea(KUTE); -// // Export the modified one. Not really required, but convenient. -// module.exports = KUTE; -// } else if(typeof window.KUTE != "undefined") { -// kute_ea(window.KUTE); -// } else { -// throw new Error("KUTE.js Bezier/Easing depends on KUTE.js. Read the docs for more info.") -// } -// })(function(KUTE){ - -(function (factory) { - if (typeof define === 'function' && define.amd) { - define(["./kute.js"], function(KUTE){ factory(KUTE); return KUTE; }); - } else if(typeof module == "object" && typeof require == "function") { - // We assume, that require() is sync. - var KUTE = require("./kute.js"); - // Export the modified one. Not really required, but convenient. - module.exports = factory(KUTE); - } else if ( typeof window.KUTE !== 'undefined' ) { - // Browser globals - window.KUTE.Ease = window.KUTE.Ease || factory(KUTE); - } else { - throw new Error("Bezier Easing functions depend on KUTE.js. Read the docs for more info."); - } -}( function (KUTE) { - 'use strict'; - var E = E || {}; - - E.Bezier = function(mX1, mY1, mX2, mY2) { - return _bz.pB(mX1, mY1, mX2, mY2); - }; - - var _bz = E.Bezier.prototype; - - // These values are established by empiricism with tests (tradeoff: performance VS precision) - _bz.ni = 4; // NEWTON_ITERATIONS - _bz.nms = 0.001; // NEWTON_MIN_SLOPE - _bz.sp = 0.0000001; // SUBDIVISION_PRECISION - _bz.smi = 10, // SUBDIVISION_MAX_ITERATIONS - - _bz.ksts = 11; // k Spline Table Size - _bz.ksss = 1.0 / (_bz.ksts - 1.0); // k Sample Step Size - - _bz.f32as = 'Float32Array' in window; // float32ArraySupported - _bz.msv = _bz.f32as ? new Float32Array (_bz.ksts) : new Array (_bz.ksts); // m Sample Values - - _bz.A = function(aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; }; - _bz.B = function(aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; }; - _bz.C = function(aA1) { return 3.0 * aA1; }; - - _bz.r = {}; - _bz.pB = function (mX1, mY1, mX2, mY2) { - this._p = false; var self = this; - - _bz.r = function(aX){ - if (!self._p) _bz.pc(mX1, mX2, mY1, mY2); - if (mX1 === mY1 && mX2 === mY2) return aX; - - if (aX === 0) return 0; - if (aX === 1) return 1; - return _bz.cB(_bz.gx(aX, mX1, mX2), mY1, mY2); - }; - return _bz.r; - }; - - // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2. - _bz.cB = function(aT, aA1, aA2) { // calc Bezier - return ((_bz.A(aA1, aA2)*aT + _bz.B(aA1, aA2))*aT + _bz.C(aA1))*aT; - }; - - // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2. - _bz.gS = function (aT, aA1, aA2) { // getSlope - return 3.0 * _bz.A(aA1, aA2)*aT*aT + 2.0 * _bz.B(aA1, aA2) * aT + _bz.C(aA1); - }; - - _bz.bS = function(a, aA, aB, mX1, mX2) { // binary Subdivide - var x, t, i = 0, j = _bz.sp, y = _bz.smi; - do { - t = aA + (aB - aA) / 2.0; - x = _bz.cB(t, mX1, mX2) - a; - if (x > 0.0) { - aB = t; - } else { - aA = t; - } - } while (Math.abs(x) > j && ++i < y); - return t; - }; - - _bz.nri = function (aX, agt, mX1, mX2) { // newton Raphs on Iterate - var i = 0, j = _bz.ni; - for (i; i < j; ++i) { - var cs = _bz.gS(agt, mX1, mX2); - if (cs === 0.0) return agt; - var x = _bz.cB(agt, mX1, mX2) - aX; - agt -= x / cs; - } - return agt; - }; - - _bz.csv = function (mX1, mX2) { // calc Sample Values - var i = 0, j = _bz.ksts; - for (i; i < j; ++i) { - _bz.msv[i] = _bz.cB(i * _bz.ksss, mX1, mX2); - } - }; - - _bz.gx = function (aX,mX1,mX2) { //get to X - var iS = 0.0, cs = 1, ls = _bz.ksts - 1; - - for (; cs != ls && _bz.msv[cs] <= aX; ++cs) { - iS += _bz.ksss; - } - --cs; - - // Interpolate to provide an initial guess for t - var dist = (aX - _bz.msv[cs]) / (_bz.msv[cs+1] - _bz.msv[cs]), - gt = iS + dist * _bz.ksss, - ins = _bz.gS(gt, mX1, mX2), - fiS = iS + _bz.ksss; - - if (ins >= _bz.nms) { - return _bz.nri(aX, gt, mX1, mX2); - } else if (ins === 0.0) { - return gt; - } else { - return _bz.bS(aX, iS, fiS, mX1, mX2); - } - }; - - _bz.pc = function(mX1, mX2, mY1, mY2) { - this._p = true; - if (mX1 != mY1 || mX2 != mY2) - _bz.csv(mX1, mX2); - }; - - // predefined bezier based easings, can be accessed via string, eg 'easeIn' or 'easeInOutQuart' - // _easings = ["linear","easeInQuad","easeOutQuad","easeInOutQuad","easeInCubic","easeOutCubic","easeInOutCubic","easeInQuart","easeInQuart","easeOutQuart","easeInOutQuart","easeInQuint","easeOutQuint","easeInOutQuint","easeInExpo","easeOutExpo","easeInOutExpo","slowMo","slowMo1","slowMo2"], - E.easeIn = function(){ return _bz.pB(0.42, 0.0, 1.00, 1.0); }; - E.easeOut = function(){ return _bz.pB(0.00, 0.0, 0.58, 1.0); }; - E.easeInOut = function(){ return _bz.pB(0.50, 0.16, 0.49, 0.86); }; - - E.easeInSine = function(){ return _bz.pB(0.47, 0, 0.745, 0.715); }; - E.easeOutSine = function(){ return _bz.pB(0.39, 0.575, 0.565, 1); }; - E.easeInOutSine = function(){ return _bz.pB(0.445, 0.05, 0.55, 0.95); }; - - E.easeInQuad = function () { return _bz.pB(0.550, 0.085, 0.680, 0.530); }; - E.easeOutQuad = function () { return _bz.pB(0.250, 0.460, 0.450, 0.940); }; - E.easeInOutQuad = function () { return _bz.pB(0.455, 0.030, 0.515, 0.955); }; - - E.easeInCubic = function () { return _bz.pB(0.55, 0.055, 0.675, 0.19); }; - E.easeOutCubic = function () { return _bz.pB(0.215, 0.61, 0.355, 1); }; - E.easeInOutCubic = function () { return _bz.pB(0.645, 0.045, 0.355, 1); }; - - E.easeInQuart = function () { return _bz.pB(0.895, 0.03, 0.685, 0.22); }; - E.easeOutQuart = function () { return _bz.pB(0.165, 0.84, 0.44, 1); }; - E.easeInOutQuart = function () { return _bz.pB(0.77, 0, 0.175, 1); }; - - E.easeInQuint = function(){ return _bz.pB(0.755, 0.05, 0.855, 0.06); }; - E.easeOutQuint = function(){ return _bz.pB(0.23, 1, 0.32, 1); }; - E.easeInOutQuint = function(){ return _bz.pB(0.86, 0, 0.07, 1); }; - - E.easeInExpo = function(){ return _bz.pB(0.95, 0.05, 0.795, 0.035); }; - E.easeOutExpo = function(){ return _bz.pB(0.19, 1, 0.22, 1); }; - E.easeInOutExpo = function(){ return _bz.pB(1, 0, 0, 1); }; - - E.easeInCirc = function(){ return _bz.pB(0.6, 0.04, 0.98, 0.335); }; - E.easeOutCirc = function(){ return _bz.pB(0.075, 0.82, 0.165, 1); }; - E.easeInOutCirc = function(){ return _bz.pB(0.785, 0.135, 0.15, 0.86); }; - - E.easeInBack = function(){ return _bz.pB(0.600, -0.280, 0.735, 0.045); }; - E.easeOutBack = function(){ return _bz.pB(0.175, 0.885, 0.320, 1.275); }; - E.easeInOutBack = function(){ return _bz.pB(0.68, -0.55, 0.265, 1.55); }; - - E.slowMo = function(){ return _bz.pB(0.000, 0.500, 1.000, 0.500); }; - E.slowMo1 = function(){ return _bz.pB(0.000, 0.700, 1.000, 0.300); }; - E.slowMo2 = function(){ return _bz.pB(0.000, 0.900, 1.000, 0.100); }; - - return E; -})); diff --git a/demo/src/kute-jquery.js b/demo/src/kute-jquery.js deleted file mode 100644 index 7dc0cbf..0000000 --- a/demo/src/kute-jquery.js +++ /dev/null @@ -1,49 +0,0 @@ -/* KUTE.js - The Light Tweening Engine - * package jQuery Plugin - * by dnp_theme - * Licensed under MIT-License - */ - - (function(factory){ - // We need to require the root KUTE and jQuery. - if (typeof define === 'function' && define.amd) { - define(["./kute.js", "jquery"], function(KUTE, $){ - factory($, KUTE); - return KUTE; - }); - } else if(typeof module == "object" && typeof require == "function") { - // We assume, that require() is sync. - var KUTE = require("./kute.js"); - var $ = require("jquery"); - - // Export the modified one. Not really required, but convenient. - module.exports = factory($, KUTE); - } else if (typeof window.KUTE !== "undefined" && (typeof window.$ !== 'undefined' || typeof window.jQuery !== 'undefined' ) ) { - // jQuery always has two ways of existing... Find one, and pass. - var $ = window.jQuery || window.$, KUTE = window.KUTE; - $.fn.KUTE = factory($, KUTE); - } else { - throw new Error("jQuery plugin for KUTE.js depends on KUTE.js and jQuery. Read the docs for more info."); - } - })(function($, KUTE) { - 'use strict'; - var $K = function( method, start, end, ops ) { // method can be fromTo(), to(), stop(), start(), chain(), pause() - var tws = [], i, l = this.length; - - for (i=0;i 0.001) { - _kpg.L = curve.b - curve.a; - curve = { - a: curve.b, - b: curve.b + _kpg.L * bounciness, - H: curve.H * bounciness * bounciness - }; - } - return curve.b; - })(); - - (function() { - var L2, b, curve, _results; - b = Math.sqrt(2 / (gravity * _kpg.L * _kpg.L)); - curve = { - a: -b, - b: b, - H: 1 - }; - if (initialForce) { - curve.a = 0; - curve.b = curve.b * 2; - } - curves.push(curve); - L2 = _kpg.L; - _results = []; - while (curve.b < 1 && curve.H > 0.001) { - L2 = curve.b - curve.a; - curve = { - a: curve.b, - b: curve.b + L2 * bounciness, - H: curve.H * elasticity - }; - _results.push(curves.push(curve)); - } - return _results; - })(); - _kpg.fn = function(t) { - var curve, i, v; - i = 0; - curve = curves[i]; - while (!(t >= curve.a && t <= curve.b)) { - i += 1; - curve = curves[i]; - if (!curve) { - break; - } - } - if (!curve) { - v = initialForce ? 0 : 1; - } else { - v = _kpg.getPointInCurve(curve.a, curve.b, curve.H, t, options, _kpg.L); - } - return v; - }; - - return _kpg.fn; - }; - - var _kpg = P.gravity.prototype; - _kpg.L = {}; - _kpg.fn = {}; - _kpg.getPointInCurve = function(a, b, H, t, o, L) { - var c, t2; - L = b - a; - t2 = (2 / L) * t - 1 - (a * 2 / L); - c = t2 * t2 * H - H + 1; - if (o.initialForce) { - c = 1 - c; - } - return c; - }; - - //throw up and pull down by gravity - P.forceWithGravity = function(o) { - var ops = o || {}; - ops.initialForce = true; - return P.gravity(ops); - }; - - - // multi point bezier - P.bezier = function(options) { - options = options || {}; - var points = options.points, - returnsToSelf = false, Bs = []; - - (function() { - var i, k; - - for (i in points) { - k = parseInt(i); - if (k >= points.length - 1) { - break; - } - _kpb.fn(points[k], points[k + 1], Bs); - } - return Bs; - })(); - - _kpb.run = function(t) { - if (t === 0) { - return 0; - } else if (t === 1) { - return 1; - } else { - return _kpb.yForX(t, Bs, returnsToSelf); - } - }; - return _kpb.run; - }; - - var _kpb = P.bezier.prototype; - _kpb.B2 = {}; - _kpb.run = {}; - - _kpb.fn = function(pointA, pointB, Bs) { - var B2 = function(t) { - return _kpb.Bezier(t, pointA, pointA.cp[pointA.cp.length - 1], pointB.cp[0], pointB); - }; - return Bs.push(B2); - }; - - _kpb.Bezier = function(t, p0, p1, p2, p3) { - return { - x: (Math.pow(1 - t, 3) * p0.x) + (3 * Math.pow(1 - t, 2) * t * p1.x) + (3 * (1 - t) * Math.pow(t, 2) * p2.x) + Math.pow(t, 3) * p3.x, - y: (Math.pow(1 - t, 3) * p0.y) + (3 * Math.pow(1 - t, 2) * t * p1.y) + (3 * (1 - t) * Math.pow(t, 2) * p2.y) + Math.pow(t, 3) * p3.y - }; - }; - - _kpb.yForX = function(xTarget, Bs, rTS) { - var B, aB, i, lower, percent, upper, x, xT, _i = 0, _len = Bs.length; - B = null; - for (_i; _i < _len; _i++) { - aB = Bs[_i]; - if (xTarget >= aB(0).x && xTarget <= aB(1).x) { - B = aB; - } - if (B !== null) { - break; - } - } - if (!B) { - return ( rTS ? 0 : 1 ); - } - xT = 0.0001; // xTolerance - lower = 0; upper = 1; - percent = (upper + lower) / 2; - x = B(percent).x; i = 0; - while (Math.abs(xTarget - x) > xT && i < 100) { - if (xTarget > x) { - lower = percent; - } else { - upper = percent; - } - percent = (upper + lower) / 2; - x = B(percent).x; - i++; - } - return B(percent).y; - }; - - P.physicsInOut = function(options) { - var friction; - options = options || {}; - friction = options.friction|| 500; - return P.bezier({ points: [ { x: 0, y: 0, cp: [ { x: 0.92 - (friction / 1000), y: 0 } ] }, { x: 1, y: 1, cp: [ { x: 0.08 + (friction / 1000), y: 1 } ] } ] }); - }; - - P.physicsIn = function(options) { - var friction; - options = options || {}; - friction = options.friction|| 500; - return P.bezier({ points: [ { x: 0, y: 0, cp: [ { x: 0.92 - (friction / 1000), y: 0 } ] }, { x: 1, y: 1, cp: [ { x: 1, y: 1 } ] } ] }); - }; - - P.physicsOut = function(options) { - var friction; - options = options || {}; - friction = options.friction|| 500; - return P.bezier({ points: [ { x: 0, y: 0, cp: [ { x: 0, y: 0 } ] }, { x: 1, y: 1, cp: [ { x: 0.08 + (friction / 1000), y: 1 } ] }] }); - }; - - P.physicsBackOut = function(options) { - var friction; - options = options || {}; - friction = options.friction|| 500; - return P.bezier({ points: [{"x":0,"y":0,"cp":[{"x":0,"y":0}]},{"x":1,"y":1,"cp":[{"x":0.735+(friction/1000),"y":1.3}]}] }); - }; - - P.physicsBackIn = function(options) { - var friction; - options = options || {}; - friction = options.friction|| 500; - return P.bezier({ points: [{"x":0,"y":0,"cp":[{"x":0.28-(friction / 1000),"y":-0.6}]},{"x":1,"y":1,"cp":[{"x":1,"y":1}]}] }); - }; - - P.physicsBackInOut = function(options) { - var friction; - options = options || {}; - friction = options.friction|| 500; - return P.bezier({ points: [{"x":0,"y":0,"cp":[{"x":0.68-(friction / 1000),"y":-0.55}]},{"x":1,"y":1,"cp":[{"x":0.265+(friction / 1000),"y":1.45}]}] }); - }; - return P; -}); diff --git a/demo/src/kute.js b/demo/src/kute.js deleted file mode 100644 index 1c50ef7..0000000 --- a/demo/src/kute.js +++ /dev/null @@ -1,902 +0,0 @@ -/* KUTE.js - The Light Tweening Engine - * by dnp_theme - * Licensed under MIT-License - */ - -(function (factory) { - if (typeof define === 'function' && define.amd) { - define([], factory); // AMD. Register as an anonymous module. - } else if (typeof exports == 'object') { - module.exports = factory(); // Node, not strict CommonJS - } else { - // Browser globals - window.KUTE = window.KUTE || factory(); - } -}( function () { - "use strict"; - var K = K || {}, _tws = [], _t = null, - _pf = getPrefix(), // prefix - _rafR = (!('requestAnimationFrame' in window)) ? true : false, // is prefix required for requestAnimationFrame - _pfT = (!('transform' in document.getElementsByTagName('div')[0].style)) ? true : false, // is prefix required for transform - _pfB = (!('border-radius' in document.getElementsByTagName('div')[0].style)) ? true : false, // is prefix required for border-radius - _tch = ('ontouchstart' in window || navigator.msMaxTouchPoints) || false, // support Touch? - _ev = _tch ? 'touchstart' : 'mousewheel', //event to prevent on scroll - - _bd = document.body, _htm = document.getElementsByTagName('HTML')[0], - _sct = (/webkit/i.test(navigator.userAgent) || document.compatMode == 'BackCompat' ? _bd : _htm), - - _isIE = (new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})").exec(navigator.userAgent) != null) ? parseFloat( RegExp.$1 ) : false, - _isIE8 = _isIE === 8, // check IE8/IE - - //assign preffix to DOM properties - _pfto = _pfT ? _pf + 'TransformOrigin' : 'transformOrigin', - _pfp = _pfT ? _pf + 'Perspective' : 'perspective', - _pfo = _pfT ? _pf + 'PerspectiveOrigin' : 'perspectiveOrigin', - _tr = _pfT ? _pf + 'Transform' : 'transform', - _br = _pfB ? _pf + 'BorderRadius' : 'borderRadius', - _brtl = _pfB ? _pf + 'BorderTopLeftRadius' : 'borderTopLeftRadius', - _brtr = _pfB ? _pf + 'BorderTopRightRadius' : 'borderTopRightRadius', - _brbl = _pfB ? _pf + 'BorderBottomLeftRadius' : 'borderBottomLeftRadius', - _brbr = _pfB ? _pf + 'BorderBottomRightRadius' : 'borderBottomRightRadius', - _raf = _rafR ? window[_pf + 'RequestAnimationFrame'] : window['requestAnimationFrame'], - _caf = _rafR ? (window[_pf + 'CancelAnimationFrame'] || window[_pf + 'CancelRequestAnimationFrame']) : window['cancelAnimationFrame'], - - //supported properties - _cls = ['color', 'backgroundColor', 'borderColor', 'borderTopColor', 'borderRightColor', 'borderBottomColor', 'borderLeftColor'], // colors 'hex', 'rgb', 'rgba' -- #fff / rgb(0,0,0) / rgba(0,0,0,0) - _sc = ['scrollTop', 'scroll'], //scroll, it has no default value, it's calculated on tween start - _clp = ['clip'], // clip - _op = ['opacity'], // opacity - _rd = ['borderRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomLeftRadius', 'borderBottomRightRadius'], // border radius px/any - _bm = ['top', 'left', 'right', 'bottom', - 'width', 'height', 'minWidth', 'minHeight', 'maxWidth', 'maxHeight', - 'padding', 'margin', 'paddingTop','paddingBottom', 'paddingLeft', 'paddingRight', 'marginTop','marginBottom', 'marginLeft', 'marginRight', - 'borderWidth', 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth'], // dimensions / box model - _tp = ['fontSize','lineHeight','letterSpacing'], // text properties - _bg = ['backgroundPosition'], // background position - _3d = ['rotateX', 'rotateY','translateZ'], // transform properties that require perspective - _tf = ['translate3d', 'translateX', 'translateY', 'translateZ', 'rotate', 'translate', 'rotateX', 'rotateY', 'rotateZ', 'skewX', 'skewY', 'scale'], // transform - _all = _cls.concat(_sc, _clp, _op, _rd, _bm, _tp, _bg, _tf), al = _all.length, - _tfS = {}, _tfE = {}, _tlS = {}, _tlE = {}, _rtS = {}, _rtE = {}, //internal temp - _d = _d || {}; //all properties default values - - //populate default values object - for ( var i=0; i< al; i++ ){ - var p = _all[i]; - if (_cls.indexOf(p) !== -1){ - _d[p] = 'rgba(0,0,0,0)'; // _d[p] = {r:0,g:0,b:0,a:1}; - } else if ( _rd.indexOf(p) !== -1 || _bm.indexOf(p) !== -1 || _tp.indexOf(p) !== -1) { - _d[p] = 0; - } else if ( _bg.indexOf(p) !== -1 ){ - _d[p] = [50,50]; - } else if ( p === 'clip' ){ - _d[p] = [0,0,0,0]; - } else if ( p === 'translate3d' ){ - _d[p] = [0,0,0]; - } else if ( p === 'translate' ){ - _d[p] = [0,0]; - } else if ( p === 'rotate' || /X|Y|Z/.test(p) ){ - _d[p] = 0; - } else if ( p === 'scale' || p === 'opacity' ){ - _d[p] = 1; - } - } - - // main methods - K.to = function (el, to, o) { - var _el = typeof el === 'object' ? el : document.querySelector(el), - _vS = to, _vE = K.prP(to, true); // we're gonna have to build _vS object at start - o = o || {}; o.rpr = true; - return new K.Tween(_el, _vS, _vE, o); - }; - - K.fromTo = function (el, f, to, o) { - var _el = typeof el === 'object' ? el : document.querySelector(el), - _vS = K.prP(f, false), _vE = K.prP(to, true); o = o || {}; - return new K.Tween(_el, _vS, _vE, o); - }; - - // multiple elements tweening - K.allTo = function (el, to, o) { - var _els = typeof el === 'object' && el.length ? el : document.querySelectorAll(el); - return new K.TweensAT(_els, to, o); - }; - K.allFromTo = function (el, f, to, o) { - var _els = typeof el === 'object' && el.length ? el : document.querySelectorAll(el); - return new K.TweensFT(_els, f, to, o); - }; - - // render functions - K._r = {}; var _r = K._r; - K._u = function(w,t) { - t = t || window.performance.now(); - if (t < w._sT && w.playing && !w.paused) { return true; } - - var p, s = s || w._sT, - d = d || w._dr, - e = ( t - s ) / d, - ve = ve || w._vE, - es = es || w._e; - e = e > 1 ? 1 : e; - - //render the CSS update - for (p in ve){ - _r[p](w,p,es(e)); - } - - if (w._uC) { w._uC.call(); } - - if (e === 1) { - if (w._r > 0) { - if ( w._r < 9999 ) { w._r--; } - - if (w._y) { w.reversed = !w.reversed; w.reverse(); } // handle yoyo - - w._sT = (w._y && !w.reversed) ? t + w._rD : t; //set the right time for delay - return true; - } else { - - if (w._cC) { w._cC.call(); } - - //stop preventing scroll when scroll tween finished - w.scrollOut(); - - // start animating chained tweens - var i = 0, ctl = w._cT.length; - for (i; i < ctl; i++) { - w._cT[i].start(w._sT + w._dr); - } - - //stop ticking when finished - w.close(); - return false; - } - } - return true; - }; - - var _u = K._u; - // internal ticker - K._t = function (t) { - var i = 0, tl; - _t = _raf(K._t); - while ( i < (tl = _tws.length) ) { - if ( _u(_tws[i],t) ) { - i++; - } else { - _tws.splice(i, 1); - } - } - return true; - }; - - // aplies the transform origin and perspective - K.perspective = function (l,w) { - if ( w._to !== undefined ) { l.style[_pfto] = w._to; } // element transform origin - if ( w._ppo !== undefined ) { l.style[_pfo] = w._ppo; } // element perspective origin - if ( w._ppp !== undefined ) { l.parentNode.style[_pfp] = w._ppp + 'px'; } // parent perspective - if ( w._pppo !== undefined ) { l.parentNode.style[_pfo] = w._pppo; } // parent perspective origin - }; - - //more internals - K.getAll = function () { return _tws; }; - K.removeAll = function () { _tws = []; }; - K.add = function (tw) { _tws.push(tw); }; - K.remove = function (tw) { - var i = _tws.indexOf(tw); - if (i !== -1) { - _tws.splice(i, 1); - } - }; - K.s = function () { _caf(_t); _t = null; }; - - // builds render functions for the render object K.render(w, p, w._e(e)); - K._queue = function (w) { - for ( var p in w._vE ) { - // checking array on every frame takes time so let's cache these - var cls = _cls.indexOf(p) !== -1, - bm = _tp.indexOf(p) !== -1 || _bm.indexOf(p) !== -1, - rd = _rd.indexOf(p) !== -1, - sc = _sc.indexOf(p) !== -1, - bg = _bg.indexOf(p) !== -1, - clp = _clp.indexOf(p) !== -1, - op = _op.indexOf(p) !== -1, - tf = p === 'transform'; - - //process styles by property / property type - if ( bm && (!(p in K._r)) ) { - K._r[p] = function(w,p,v) { - w._el.style[p] = (w._vS[p].value + (w._vE[p].value - w._vS[p].value) * v ) + w._vE[p].unit; - }; - } else if ( rd && (!(p in K._r)) ) { - if (p === 'borderRadius') { - K._r[p] = function(w,p,v) { - w._el.style[_br] = (w._vS[p].value + (w._vE[p].value - w._vS[p].value) * v ) + w._vE[p].unit; - }; - } else if (p === 'borderTopLeftRadius') { - K._r[p] = function(w,p,v) { - w._el.style[_brtl] = (w._vS[p].value + (w._vE[p].value - w._vS[p].value) * v ) + w._vE[p].unit; - }; - } else if (p === 'borderTopRightRadius') { - K._r[p] = function(w,p,v) { - w._el.style[_brtr] = (w._vS[p].value + (w._vE[p].value - w._vS[p].value) * v ) + w._vE[p].unit; - }; - } else if (p === 'borderBottomLeftRadius') { - K._r[p] = function(w,p,v) { - w._el.style[_brbl] = (w._vS[p].value + (w._vE[p].value - w._vS[p].value) * v ) + w._vE[p].unit; - }; - } else if (p === 'borderBottomRightRadius') { - K._r[p] = function(w,p,v) { - w._el.style[_brbr] = (w._vS[p].value + (w._vE[p].value - w._vS[p].value) * v ) + w._vE[p].unit; - }; - } - } else if (tf && (!(p in K._r)) ) { - - K._r[p] = function(w,p,v) { - var _tS = '', tP, rps, pps = 'perspective('+w._pp+'px) '; - for (tP in w._vE[p]) { - var t1 = w._vS[p][tP], t2 = w._vE[p][tP]; - rps = rps || _3d.indexOf(tP) !== -1 && !_isIE; - - if ( tP === 'translate' ) { - var tls = '', ts = {}, ax; - - for (ax in t2){ - var x1 = t1[ax].value || 0, x2 = t2[ax].value || 0, xu = t2[ax].unit || 'px'; - ts[ax] = x1===x2 ? x2+xu : (x1 + ( x2 - x1 ) * v) + xu; - } - tls = t2.x ? 'translate(' + ts.x + ',' + ts.y + ')' : - 'translate3d(' + ts.translateX + ',' + ts.translateY + ',' + ts.translateZ + ')'; - - _tS = (_tS === '') ? tls : (tls + ' ' + _tS); - } else if ( tP === 'rotate' ) { - var rt = '', rS = {}, rx; - - for ( rx in t2 ){ - if ( t1[rx] ) { - var a1 = t1[rx].value, a2 = t2[rx].value, au = t2[rx].unit||'deg', - av = a1 + (a2 - a1) * v; - rS[rx] = rx ==='z' ? 'rotate('+av+au+')' : rx + '(' + av + au + ') '; - } - } - rt = t2.z ? rS.z : (rS.rotateX||'') + (rS.rotateY||'') + (rS.rotateZ||''); - - _tS = (_tS === '') ? rt : (_tS + ' ' + rt); - } else if (tP==='skew') { - var sk = '', sS = {}; - for ( var sx in t2 ){ - if ( t1[sx] ) { - var s1 = t1[sx].value, s2 = t2[sx].value, su = t2[sx].unit||'deg', - sv = s1 + (s2 - s1) * v; - sS[sx] = sx + '(' + sv + su + ') '; - } - } - sk = (sS.skewX||'') + (sS.skewY||''); - _tS = (_tS === '') ? sk : (_tS + ' ' + sk); - } else if (tP === 'scale') { - var sc1 = t1.value, sc2 = t2.value, - s = sc1 + (sc2 - sc1) * v, scS = tP + '(' + s + ')'; - _tS = (_tS === '') ? scS : (_tS + ' ' + scS); - } - } - w._el.style[_tr] = rps || ( w._pp !== undefined && w._pp !== 0 ) ? pps + _tS : _tS; - }; - - } else if ( cls && (!(p in K._r)) ) { - K._r[p] = function(w,p,v) { - var _c = {}; - for (var c in w._vE[p].value) { - if ( c !== 'a' ){ - _c[c] = parseInt(w._vS[p].value[c] + (w._vE[p].value[c] - w._vS[p].value[c]) * v )||0; - } else { - _c[c] = (w._vS[p].value[c] && w._vE[p].value[c]) ? parseFloat(w._vS[p].value[c] + (w._vE[p].value[c] - w._vS[p].value[c]) * v) : null; - } - } - - if ( w._hex ) { - w._el.style[p] = K.rth( parseInt(_c.r), parseInt(_c.g), parseInt(_c.b) ); - } else { - w._el.style[p] = !_c.a || _isIE8 ? 'rgb(' + _c.r + ',' + _c.g + ',' + _c.b + ')' : 'rgba(' + _c.r + ',' + _c.g + ',' + _c.b + ',' + _c.a + ')'; - } - }; - } else if ( sc && (!(p in K._r)) ) { - K._r[p] = function(w,p,v) { - w._el = (w._el === undefined || w._el === null) ? _sct : w._el; - w._el.scrollTop = w._vS[p].value + (w._vE[p].value - w._vS[p].value) * v; - }; - } else if ( bg && (!(p in K._r)) ) { - K._r[p] = function(w,p,v) { - var px1 = w._vS[p].x.v, px2 = w._vE[p].x.v, py1 = w._vS[p].y.v, py2 = w._vE[p].y.v, - px = (px1 + ( px2 - px1 ) * v), pxu = '%', py = (py1 + ( py2 - py1 ) * v), pyu = '%'; - w._el.style[p] = px + pxu + ' ' + py + pyu; - }; - } else if ( clp && (!(p in K._r)) ) { - K._r[p] = function(w,p,v) { - var h = 0, cl = []; - for (h;h<4;h++){ - var c1 = w._vS[p][h].v, c2 = w._vE[p][h].v, cu = w._vE[p][h].u || 'px'; - cl[h] = ((c1 + ( c2 - c1 ) * v)) + cu; - } - w._el.style[p] = 'rect('+cl+')'; - }; - } else if ( op && (!(p in K._r)) ) { - if (_isIE8) { - K._r[p] = function(w,p,v) { - w._el.style.filter = "alpha(opacity=" + ( w._vS[p].value + (w._vE[p].value - w._vS[p].value) * v) * 100 + ")"; - }; - } else { - K._r[p] = function(w,p,v) { - w._el.style.opacity = w._vS[p].value + (w._vE[p].value - w._vS[p].value) * v; - }; - } - } - } - }; - - // process properties - K.prP = function (t, e) { // process tween properties for .fromTo() method - var _st = {}, - tr = e === true ? _tfE : _tfS, - tl = e === true ? _tlE : _tlS, - rt = e === true ? _rtE : _rtS; - - tl = {}; tr = {}; - - for (var x in t) { - if (_tf.indexOf(x) !== -1) { - - if (x !== 'translate' && /translate/.test(x)) { //process translate3d - var ta = ['X', 'Y', 'Z'], f = 0; //coordinates // translate[x] = pp(x, t[x]); - - for (f; f < 3; f++) { - var a = ta[f]; - if ( /3d/.test(x) ) { - tl['translate' + a] = K.pp('translate' + a, t[x][f]); - } else { - tl['translate' + a] = ('translate' + a in t) ? K.pp('translate' + a, t['translate' + a]) : { value: 0, unit: 'px' }; - } - } - - tr['translate'] = tl; - } else if ( x !== 'rotate' && /rotate|skew/.test(x)) { //process rotation - var ap = /rotate/.test(x) ? 'rotate' : 'skew', ra = ['X', 'Y', 'Z'], r = 0, - _rt = {}, _sk = {}, rt = ap === 'rotate' ? _rt : _sk; - for (r; r < 3; r++) { - var v = ra[r]; - if ( t[ap+v] !== undefined && x !== 'skewZ' ) { - rt[ap+v] = K.pp(ap + v, t[ap+v]); - } - } - - tr[ap] = rt; - } else if ( x === 'translate' || x === 'rotate' || x === 'scale' ) { //process 2d translation / rotation - tr[x] = K.pp(x, t[x]); - } - - _st['transform'] = tr; - - } else if (_tf.indexOf(x) === -1) { - _st[x] = K.pp(x, t[x]); - } - } - return _st; - }; - - // _cls _sc _op _bm _tp _bg _tf - K.pp = function(p, v) {//process single property - if (_tf.indexOf(p) !== -1) { - var t = p.replace(/X|Y|Z/, ''), tv; - if (p === 'translate3d') { - tv = v.split(','); - return { - translateX : { value: K.truD(tv[0]).v, unit: K.truD(tv[0]).u }, - translateY : { value: K.truD(tv[1]).v, unit: K.truD(tv[1]).u }, - translateZ : { value: K.truD(tv[2]).v, unit: K.truD(tv[2]).u } - }; - } else if (p !== 'translate' && t === 'translate') { - return { value: K.truD(v).v, unit: (K.truD(v).u||'px') }; - } else if (p !== 'rotate' && (t === 'skew' || t === 'rotate') && p !== 'skewZ' ) { - return { value: K.truD(v).v, unit: (K.truD(v,p).u||'deg') }; - } else if (p === 'translate') { - tv = typeof v === 'string' ? v.split(',') : v; var t2d = {}; - if (tv instanceof Array) { - t2d.x = { value: K.truD(tv[0]).v, unit: K.truD(tv[0]).u }, - t2d.y = { value: K.truD(tv[1]).v, unit: K.truD(tv[1]).u } - } else { - t2d.x = { value: K.truD(tv).v, unit: K.truD(tv).u }, - t2d.y = { value: 0, unit: 'px' } - } - return t2d; - } else if (p === 'rotate') { - var r2d = {}; - r2d.z = { value: parseInt(v, 10), unit: (K.truD(v,p).u||'deg') }; - return r2d; - } else if (p === 'scale') { - return { value: parseFloat(v, 10) }; - } - } - if (_tp.indexOf(p) !== -1 || _bm.indexOf(p) !== -1) { - return { value: K.truD(v).v, unit: K.truD(v).u }; - } - if (_op.indexOf(p) !== -1) { - return { value: parseFloat(v, 10) }; - } - if (_sc.indexOf(p) !== -1) { - return { value: parseFloat(v, 10) }; - } - if (_clp.indexOf(p) !== -1) { - if ( v instanceof Array ){ - return [ K.truD(v[0]), K.truD(v[1]), K.truD(v[2]), K.truD(v[3]) ]; - } else { - var ci; - if ( /rect/.test(v) ) { - ci = v.replace(/rect|\(|\)/g,'').split(/\s|\,/); - } else if ( /auto|none|initial/.test(v) ){ - ci = _d[p]; - } - return [ K.truD(ci[0]), K.truD(ci[1]), K.truD(ci[2]), K.truD(ci[3]) ]; - } - } - if (_cls.indexOf(p) !== -1) { - return { value: K.truC(v) }; - } - if (_bg.indexOf(p) !== -1) { - if ( v instanceof Array ){ - return { x: K.truD(v[0])||{ v: 50, u: '%' }, y: K.truD(v[1])||{ v: 50, u: '%' } }; - } else { - var posxy = v.replace(/top|left/g,0).replace(/right|bottom/g,100).replace(/center|middle/,50).split(/\s|\,/g), - xp = K.truD(posxy[0]), yp = K.truD(posxy[1]); - return { x: xp, y: yp }; - } - } - if (_rd.indexOf(p) !== -1) { - var rad = K.truD(v); - return { value: rad.v, unit: rad.u }; - } - }; - - K.truD = function (d,p) { //true dimension returns { v = value, u = unit } - var x = parseInt(d) || 0, mu = ['px','%','deg','rad','em','rem','vh','vw'], l = mu.length, - y = getU(); - function getU() { - var u,i=0; - for (i;i 0) { self._r = self.repeat; } - if (self._y && self.reversed===true) { self.reverse(); self.reversed = false; } - self.playing = false; - },61) - }; - - // the multi elements Tween constructs - K.TweensAT = function (els, vE, o) { // .to - this.tweens = []; var i, tl = els.length, _o = []; - for ( i = 0; i < tl; i++ ) { - _o[i] = o || {}; o.delay = o.delay || 0; - _o[i].delay = i>0 ? o.delay + (o.offset||0) : o.delay; - this.tweens.push( K.to(els[i], vE, _o[i]) ); - } - }; - K.TweensFT = function (els, vS, vE, o) { // .fromTo - this.tweens = []; var i, tl = els.length, _o = []; - for ( i = 0; i < tl; i++ ) { - _o[i] = o || {}; o.delay = o.delay || 0; - _o[i].delay = i>0 ? o.delay + (o.offset||0) : o.delay; - this.tweens.push( K.fromTo(els[i], vS, vE, _o[i]) ); - } - }; - var ws = K.TweensAT.prototype = K.TweensFT.prototype; - ws.start = function(t){ - t = t || window.performance.now(); - var i, tl = this.tweens.length; - for ( i = 0; i < tl; i++ ) { - this.tweens[i].start(t); - } - return this; - } - ws.stop = function(){ for ( var i = 0; i < this.tweens.length; i++ ) { this.tweens[i].stop(); } return this; } - ws.pause = function(){ for ( var i = 0; i < this.tweens.length; i++ ) { this.tweens[i].pause(); } return this; } - ws.play = ws.resume = function(){ for ( var i = 0; i < this.tweens.length; i++ ) { this.tweens[i].play(); } return this; } - - - //returns browser prefix - function getPrefix() { - var div = document.createElement('div'), i = 0, pf = ['Moz', 'moz', 'Webkit', 'webkit', 'O', 'o', 'Ms', 'ms'], pl = pf.length, - s = ['MozTransform', 'mozTransform', 'WebkitTransform', 'webkitTransform', 'OTransform', 'oTransform', 'MsTransform', 'msTransform']; - - for (i; i < pl; i++) { if (s[i] in div.style) { return pf[i]; } } - div = null; - } - - return K; -})); \ No newline at end of file diff --git a/dist/kute-bezier.min.js b/dist/kute-bezier.min.js deleted file mode 100644 index 7d2686d..0000000 --- a/dist/kute-bezier.min.js +++ /dev/null @@ -1,2 +0,0 @@ -// bezier easing for KUTE.js | dnp_theme | MIT License -!function(n){if("function"==typeof define&&define.amd)define(["./kute.js"],function(e){return n(e),e});else if("object"==typeof module&&"function"==typeof require){var e=require("./kute.js");module.exports=n(e)}else{if("undefined"==typeof window.KUTE)throw new Error("Bezier Easing functions depend on KUTE.js. Read the docs for more info.");window.KUTE.Ease=window.KUTE.Ease||n(e)}}(function(n){"use strict";var e=e||{};e.Bezier=function(n,e,r,u){return t.pB(n,e,r,u)};var t=e.Bezier.prototype;return t.ni=4,t.nms=.001,t.sp=1e-7,t.smi=10,t.ksts=11,t.ksss=1/(t.ksts-1),t.f32as="Float32Array"in window,t.msv=t.f32as?new Float32Array(t.ksts):new Array(t.ksts),t.A=function(n,e){return 1-3*e+3*n},t.B=function(n,e){return 3*e-6*n},t.C=function(n){return 3*n},t.r={},t.pB=function(n,e,r,u){this._p=!1;var i=this;return t.r=function(s){return i._p||t.pc(n,r,e,u),n===e&&r===u?s:0===s?0:1===s?1:t.cB(t.gx(s,n,r),e,u)},t.r},t.cB=function(n,e,r){return((t.A(e,r)*n+t.B(e,r))*n+t.C(e))*n},t.gS=function(n,e,r){return 3*t.A(e,r)*n*n+2*t.B(e,r)*n+t.C(e)},t.bS=function(n,e,r,u,i){var s,o,c=0,f=t.sp,a=t.smi;do o=e+(r-e)/2,s=t.cB(o,u,i)-n,s>0?r=o:e=o;while(Math.abs(s)>f&&++ci;++i){var o=t.gS(e,r,u);if(0===o)return e;var c=t.cB(e,r,u)-n;e-=c/o}return e},t.csv=function(n,e){var r=0,u=t.ksts;for(r;u>r;++r)t.msv[r]=t.cB(r*t.ksss,n,e)},t.gx=function(n,e,r){for(var u=0,i=1,s=t.ksts-1;i!=s&&t.msv[i]<=n;++i)u+=t.ksss;--i;var o=(n-t.msv[i])/(t.msv[i+1]-t.msv[i]),c=u+o*t.ksss,f=t.gS(c,e,r),a=u+t.ksss;return f>=t.nms?t.nri(n,c,e,r):0===f?c:t.bS(n,u,a,e,r)},t.pc=function(n,e,r,u){this._p=!0,(n!=r||e!=u)&&t.csv(n,e)},e.easeIn=function(){return t.pB(.42,0,1,1)},e.easeOut=function(){return t.pB(0,0,.58,1)},e.easeInOut=function(){return t.pB(.5,.16,.49,.86)},e.easeInSine=function(){return t.pB(.47,0,.745,.715)},e.easeOutSine=function(){return t.pB(.39,.575,.565,1)},e.easeInOutSine=function(){return t.pB(.445,.05,.55,.95)},e.easeInQuad=function(){return t.pB(.55,.085,.68,.53)},e.easeOutQuad=function(){return t.pB(.25,.46,.45,.94)},e.easeInOutQuad=function(){return t.pB(.455,.03,.515,.955)},e.easeInCubic=function(){return t.pB(.55,.055,.675,.19)},e.easeOutCubic=function(){return t.pB(.215,.61,.355,1)},e.easeInOutCubic=function(){return t.pB(.645,.045,.355,1)},e.easeInQuart=function(){return t.pB(.895,.03,.685,.22)},e.easeOutQuart=function(){return t.pB(.165,.84,.44,1)},e.easeInOutQuart=function(){return t.pB(.77,0,.175,1)},e.easeInQuint=function(){return t.pB(.755,.05,.855,.06)},e.easeOutQuint=function(){return t.pB(.23,1,.32,1)},e.easeInOutQuint=function(){return t.pB(.86,0,.07,1)},e.easeInExpo=function(){return t.pB(.95,.05,.795,.035)},e.easeOutExpo=function(){return t.pB(.19,1,.22,1)},e.easeInOutExpo=function(){return t.pB(1,0,0,1)},e.easeInCirc=function(){return t.pB(.6,.04,.98,.335)},e.easeOutCirc=function(){return t.pB(.075,.82,.165,1)},e.easeInOutCirc=function(){return t.pB(.785,.135,.15,.86)},e.easeInBack=function(){return t.pB(.6,-.28,.735,.045)},e.easeOutBack=function(){return t.pB(.175,.885,.32,1.275)},e.easeInOutBack=function(){return t.pB(.68,-.55,.265,1.55)},e.slowMo=function(){return t.pB(0,.5,1,.5)},e.slowMo1=function(){return t.pB(0,.7,1,.3)},e.slowMo2=function(){return t.pB(0,.9,1,.1)},e}); \ No newline at end of file diff --git a/dist/kute-jquery.min.js b/dist/kute-jquery.min.js deleted file mode 100644 index 8be754f..0000000 --- a/dist/kute-jquery.min.js +++ /dev/null @@ -1,2 +0,0 @@ -// KUTE jQuery Plugin for KUTE.js | by dnp_theme | License - MIT -!function(e){if("function"==typeof define&&define.amd)define(["./kute.js","jquery"],function(n,i){return e(i,n),n});else if("object"==typeof module&&"function"==typeof require){var n=require("./kute.js"),i=require("jquery");module.exports=e(i,n)}else{if("undefined"==typeof window.KUTE||"undefined"==typeof window.$&&"undefined"==typeof window.jQuery)throw new Error("jQuery plugin for KUTE.js depends on KUTE.js and jQuery. Read the docs for more info.");var i=window.jQuery||window.$,n=window.KUTE;i.fn.KUTE=e(i,n)}}(function(e,n){"use strict";var i=function(e,i,o,t){var r,u=[],f=this.length;for(r=0;f>r;r++){var d=this[r][e];"function"==typeof d&&d.apply(this[r]),"to"===e?u.push(new n[e](this[r],i,o)):"fromTo"===e||"Animate"===e?u.push(new n[e](this[r],i,o,t)):"chain"===e&&this[r].chain.apply(this[r],i)}return u};return i}); \ No newline at end of file diff --git a/dist/kute-physics.min.js b/dist/kute-physics.min.js deleted file mode 100644 index 4c6e359..0000000 --- a/dist/kute-physics.min.js +++ /dev/null @@ -1,2 +0,0 @@ -// dynamics easings KUTE.js | dnp_theme | MIT License -!function(n){if("function"==typeof define&&define.amd)define(["./kute.js"],function(r){return n(r),r});else if("object"==typeof module&&"function"==typeof require){var r=require("./kute.js");module.exports=n(r)}else{if("undefined"==typeof window.KUTE)throw new Error("Physics Easing functions for KUTE.js depend on KUTE.js. Read the docs for more info.");window.KUTE.Physics=window.KUTE.Physics||n(r)}}(function(n){"use strict";var r=r||{},t=Math.PI/2;r.spring=function(n){n=n||{};var r=Math.max(1,(n.frequency||300)/20),t=Math.pow(20,(n.friction||200)/100),i=n.anticipationStrength||0,o=(n.anticipationSize||0)/1e3;return e.run=function(n){var u,c,a,f,p,y,s,h;return y=n/(1-o)-o/(1-o),o>n?(h=o/(1-o)-o/(1-o),s=0/(1-o)-o/(1-o),p=Math.acos(1/e.A1(n,h)),a=(Math.acos(1/e.A1(n,s))-p)/(r*-o),u=e.A1):(u=e.A2,p=0,a=1),c=u(y,o,i,t),f=r*(n-o)*a+p,1-c*Math.cos(f)},e.run};var e=r.spring.prototype;e.run={},e.A1=function(n,r,t){var e,i,o,u;return o=r/(1-r),u=0,i=(o-.8*u)/(o-u),e=(.8-i)/o,e*n*t/100+i},e.A2=function(n,r,t,e){return Math.pow(e/10,-n)*(1-n)},r.bounce=function(n){n=n||{};var r=Math.max(1,(n.frequency||300)/20),e=Math.pow(20,(n.friction||200)/100);return i.run=function(n){var i=Math.pow(e/10,-n)*(1-n),o=r*n*1+t;return i*Math.cos(o)},i.run};var i=r.bounce.prototype;i.run={},r.gravity=function(n){var r,t,e,i,u;return n=n||{},r=(n.bounciness||400)/1250,e=(n.elasticity||200)/1e3,u=n.initialForce||!1,i=100,t=[],o.L=function(){var n,t;for(n=Math.sqrt(2/i),t={a:-n,b:n,H:1},u&&(t.a=0,t.b=2*t.b);t.H>.001;)o.L=t.b-t.a,t={a:t.b,b:t.b+o.L*r,H:t.H*r*r};return t.b}(),function(){var n,c,a,f;for(c=Math.sqrt(2/(i*o.L*o.L)),a={a:-c,b:c,H:1},u&&(a.a=0,a.b=2*a.b),t.push(a),n=o.L,f=[];a.b<1&&a.H>.001;)n=a.b-a.a,a={a:a.b,b:a.b+n*r,H:a.H*e},f.push(t.push(a));return f}(),o.fn=function(r){var e,i,c;for(i=0,e=t[i];!(r>=e.a&&r<=e.b)&&(i+=1,e=t[i]););return c=e?o.getPointInCurve(e.a,e.b,e.H,r,n,o.L):u?0:1},o.fn};var o=r.gravity.prototype;o.L={},o.fn={},o.getPointInCurve=function(n,r,t,e,i,o){var u,c;return o=r-n,c=2/o*e-1-2*n/o,u=c*c*t-t+1,i.initialForce&&(u=1-u),u},r.forceWithGravity=function(n){var t=n||{};return t.initialForce=!0,r.gravity(t)},r.bezier=function(n){n=n||{};var r=n.points,t=!1,e=[];return function(){var n,t;for(n in r){if(t=parseInt(n),t>=r.length-1)break;u.fn(r[t],r[t+1],e)}return e}(),u.run=function(n){return 0===n?0:1===n?1:u.yForX(n,e,t)},u.run};var u=r.bezier.prototype;return u.B2={},u.run={},u.fn=function(n,r,t){var e=function(t){return u.Bezier(t,n,n.cp[n.cp.length-1],r.cp[0],r)};return t.push(e)},u.Bezier=function(n,r,t,e,i){return{x:Math.pow(1-n,3)*r.x+3*Math.pow(1-n,2)*n*t.x+3*(1-n)*Math.pow(n,2)*e.x+Math.pow(n,3)*i.x,y:Math.pow(1-n,3)*r.y+3*Math.pow(1-n,2)*n*t.y+3*(1-n)*Math.pow(n,2)*e.y+Math.pow(n,3)*i.y}},u.yForX=function(n,r,t){var e,i,o,u,c,a,f,p,y=0,s=r.length;for(e=null,y;s>y&&(i=r[y],n>=i(0).x&&n<=i(1).x&&(e=i),null===e);y++);if(!e)return t?0:1;for(p=1e-4,u=0,a=1,c=(a+u)/2,f=e(c).x,o=0;Math.abs(n-f)>p&&100>o;)n>f?u=c:a=c,c=(a+u)/2,f=e(c).x,o++;return e(c).y},r.physicsInOut=function(n){var t;return n=n||{},t=n.friction||500,r.bezier({points:[{x:0,y:0,cp:[{x:.92-t/1e3,y:0}]},{x:1,y:1,cp:[{x:.08+t/1e3,y:1}]}]})},r.physicsIn=function(n){var t;return n=n||{},t=n.friction||500,r.bezier({points:[{x:0,y:0,cp:[{x:.92-t/1e3,y:0}]},{x:1,y:1,cp:[{x:1,y:1}]}]})},r.physicsOut=function(n){var t;return n=n||{},t=n.friction||500,r.bezier({points:[{x:0,y:0,cp:[{x:0,y:0}]},{x:1,y:1,cp:[{x:.08+t/1e3,y:1}]}]})},r.physicsBackOut=function(n){var t;return n=n||{},t=n.friction||500,r.bezier({points:[{x:0,y:0,cp:[{x:0,y:0}]},{x:1,y:1,cp:[{x:.735+t/1e3,y:1.3}]}]})},r.physicsBackIn=function(n){var t;return n=n||{},t=n.friction||500,r.bezier({points:[{x:0,y:0,cp:[{x:.28-t/1e3,y:-.6}]},{x:1,y:1,cp:[{x:1,y:1}]}]})},r.physicsBackInOut=function(n){var t;return n=n||{},t=n.friction||500,r.bezier({points:[{x:0,y:0,cp:[{x:.68-t/1e3,y:-.55}]},{x:1,y:1,cp:[{x:.265+t/1e3,y:1.45}]}]})},r}); \ No newline at end of file diff --git a/dist/kute.min.js b/dist/kute.min.js deleted file mode 100644 index 02e636b..0000000 --- a/dist/kute.min.js +++ /dev/null @@ -1,2 +0,0 @@ -// KUTE.js | dnp_theme | MIT-License -!function(t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():window.KUTE=window.KUTE||t()}(function(){"use strict";function t(){var t=document.createElement("div"),e=0,r=["Moz","moz","Webkit","webkit","O","o","Ms","ms"],n=r.length,i=["MozTransform","mozTransform","WebkitTransform","webkitTransform","OTransform","oTransform","MsTransform","msTransform"];for(e;n>e;e++)if(i[e]in t.style)return r[e];t=null}for(var e=e||{},r=[],n=null,i=t(),a=("requestAnimationFrame"in window?!1:!0),s=("transform"in document.getElementsByTagName("div")[0].style?!1:!0),o=("border-radius"in document.getElementsByTagName("div")[0].style?!1:!0),u=("ontouchstart"in window||navigator.msMaxTouchPoints||!1),l=u?"touchstart":"mousewheel",v=document.body,f=document.getElementsByTagName("HTML")[0],p=/webkit/i.test(navigator.userAgent)||"BackCompat"==document.compatMode?v:f,c=null!=new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})").exec(navigator.userAgent)?parseFloat(RegExp.$1):!1,d=8===c,h=s?i+"TransformOrigin":"transformOrigin",_=s?i+"Perspective":"perspective",g=s?i+"PerspectiveOrigin":"perspectiveOrigin",m=s?i+"Transform":"transform",y=o?i+"BorderRadius":"borderRadius",w=o?i+"BorderTopLeftRadius":"borderTopLeftRadius",T=o?i+"BorderTopRightRadius":"borderTopRightRadius",S=o?i+"BorderBottomLeftRadius":"borderBottomLeftRadius",b=o?i+"BorderBottomRightRadius":"borderBottomRightRadius",O=a?window[i+"RequestAnimationFrame"]:window.requestAnimationFrame,E=a?window[i+"CancelAnimationFrame"]||window[i+"CancelRequestAnimationFrame"]:window.cancelAnimationFrame,x=["color","backgroundColor","borderColor","borderTopColor","borderRightColor","borderBottomColor","borderLeftColor"],C=["scrollTop","scroll"],I=["clip"],R=["opacity"],D=["borderRadius","borderTopLeftRadius","borderTopRightRadius","borderBottomLeftRadius","borderBottomRightRadius"],M=["top","left","right","bottom","width","height","minWidth","minHeight","maxWidth","maxHeight","padding","margin","paddingTop","paddingBottom","paddingLeft","paddingRight","marginTop","marginBottom","marginLeft","marginRight","borderWidth","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth"],B=["fontSize","lineHeight","letterSpacing"],k=["backgroundPosition"],A=["rotateX","rotateY","translateZ"],F=["translate3d","translateX","translateY","translateZ","rotate","translate","rotateX","rotateY","rotateZ","skewX","skewY","scale"],L=x.concat(C,I,R,D,M,B,k,F),P=L.length,q={},Y={},X={},Z={},z={},Q={},W=W||{},j=0;P>j;j++){var H=L[j];-1!==x.indexOf(H)?W[H]="rgba(0,0,0,0)":-1!==D.indexOf(H)||-1!==M.indexOf(H)||-1!==B.indexOf(H)?W[H]=0:-1!==k.indexOf(H)?W[H]=[50,50]:"clip"===H?W[H]=[0,0,0,0]:"translate3d"===H?W[H]=[0,0,0]:"translate"===H?W[H]=[0,0]:"rotate"===H||/X|Y|Z/.test(H)?W[H]=0:("scale"===H||"opacity"===H)&&(W[H]=1)}e.to=function(t,r,n){var i="object"==typeof t?t:document.querySelector(t),a=r,s=e.prP(r,!0);return n=n||{},n.rpr=!0,new e.Tween(i,a,s,n)},e.fromTo=function(t,r,n,i){var a="object"==typeof t?t:document.querySelector(t),s=e.prP(r,!1),o=e.prP(n,!0);return i=i||{},new e.Tween(a,s,o,i)},e.allTo=function(t,r,n){var i="object"==typeof t&&t.length?t:document.querySelectorAll(t);return new e.TweensAT(i,r,n)},e.allFromTo=function(t,r,n,i){var a="object"==typeof t&&t.length?t:document.querySelectorAll(t);return new e.TweensFT(a,r,n,i)},e._r={};var N=e._r;e._u=function(t,e){if(e=e||window.performance.now(),e1?1:a;for(r in s)N[r](t,r,o(a));if(t._uC&&t._uC.call(),1===a){if(t._r>0)return t._r<9999&&t._r--,t._y&&(t.reversed=!t.reversed,t.reverse()),t._sT=t._y&&!t.reversed?e+t._rD:e,!0;t._cC&&t._cC.call(),t.scrollOut();var u=0,l=t._cT.length;for(u;l>u;u++)t._cT[u].start(t._sT+t._dr);return t.close(),!1}return!0};var $=e._u;e._t=function(t){var i,a=0;for(n=O(e._t);a<(i=r.length);)$(r[a],t)?a++:r.splice(a,1);return!0},e.perspective=function(t,e){void 0!==e._to&&(t.style[h]=e._to),void 0!==e._ppo&&(t.style[g]=e._ppo),void 0!==e._ppp&&(t.parentNode.style[_]=e._ppp+"px"),void 0!==e._pppo&&(t.parentNode.style[g]=e._pppo)},e.getAll=function(){return r},e.removeAll=function(){r=[]},e.add=function(t){r.push(t)},e.remove=function(t){var e=r.indexOf(t);-1!==e&&r.splice(e,1)},e.s=function(){E(n),n=null},e._queue=function(t){for(var r in t._vE){var n=-1!==x.indexOf(r),i=-1!==B.indexOf(r)||-1!==M.indexOf(r),a=-1!==D.indexOf(r),s=-1!==C.indexOf(r),o=-1!==k.indexOf(r),u=-1!==I.indexOf(r),l=-1!==R.indexOf(r),v="transform"===r;!i||r in e._r?!a||r in e._r?!v||r in e._r?!n||r in e._r?!s||r in e._r?!o||r in e._r?!u||r in e._r?!l||r in e._r||(d?e._r[r]=function(t,e,r){t._el.style.filter="alpha(opacity="+100*(t._vS[e].value+(t._vE[e].value-t._vS[e].value)*r)+")"}:e._r[r]=function(t,e,r){t._el.style.opacity=t._vS[e].value+(t._vE[e].value-t._vS[e].value)*r}):e._r[r]=function(t,e,r){var n=0,i=[];for(n;4>n;n++){var a=t._vS[e][n].v,s=t._vE[e][n].v,o=t._vE[e][n].u||"px";i[n]=a+(s-a)*r+o}t._el.style[e]="rect("+i+")"}:e._r[r]=function(t,e,r){var n=t._vS[e].x.v,i=t._vE[e].x.v,a=t._vS[e].y.v,s=t._vE[e].y.v,o=n+(i-n)*r,u="%",l=a+(s-a)*r,v="%";t._el.style[e]=o+u+" "+l+v}:e._r[r]=function(t,e,r){t._el=void 0===t._el||null===t._el?p:t._el,t._el.scrollTop=t._vS[e].value+(t._vE[e].value-t._vS[e].value)*r}:e._r[r]=function(t,r,n){var i={};for(var a in t._vE[r].value)"a"!==a?i[a]=parseInt(t._vS[r].value[a]+(t._vE[r].value[a]-t._vS[r].value[a])*n)||0:i[a]=t._vS[r].value[a]&&t._vE[r].value[a]?parseFloat(t._vS[r].value[a]+(t._vE[r].value[a]-t._vS[r].value[a])*n):null;t._hex?t._el.style[r]=e.rth(parseInt(i.r),parseInt(i.g),parseInt(i.b)):t._el.style[r]=!i.a||d?"rgb("+i.r+","+i.g+","+i.b+")":"rgba("+i.r+","+i.g+","+i.b+","+i.a+")"}:e._r[r]=function(t,e,r){var n,i,a="",s="perspective("+t._pp+"px) ";for(n in t._vE[e]){var o=t._vS[e][n],u=t._vE[e][n];if(i=i||-1!==A.indexOf(n)&&!c,"translate"===n){var l,v="",f={};for(l in u){var p=o[l].value||0,d=u[l].value||0,h=u[l].unit||"px";f[l]=p===d?d+h:p+(d-p)*r+h}v=u.x?"translate("+f.x+","+f.y+")":"translate3d("+f.translateX+","+f.translateY+","+f.translateZ+")",a=""===a?v:v+" "+a}else if("rotate"===n){var _,g="",y={};for(_ in u)if(o[_]){var w=o[_].value,T=u[_].value,S=u[_].unit||"deg",b=w+(T-w)*r;y[_]="z"===_?"rotate("+b+S+")":_+"("+b+S+") "}g=u.z?y.z:(y.rotateX||"")+(y.rotateY||"")+(y.rotateZ||""),a=""===a?g:a+" "+g}else if("skew"===n){var O="",E={};for(var x in u)if(o[x]){var C=o[x].value,I=u[x].value,R=u[x].unit||"deg",D=C+(I-C)*r;E[x]=x+"("+D+R+") "}O=(E.skewX||"")+(E.skewY||""),a=""===a?O:a+" "+O}else if("scale"===n){var M=o.value,B=u.value,k=M+(B-M)*r,F=n+"("+k+")";a=""===a?F:a+" "+F}}t._el.style[m]=i||void 0!==t._pp&&0!==t._pp?s+a:a}:"borderRadius"===r?e._r[r]=function(t,e,r){t._el.style[y]=t._vS[e].value+(t._vE[e].value-t._vS[e].value)*r+t._vE[e].unit}:"borderTopLeftRadius"===r?e._r[r]=function(t,e,r){t._el.style[w]=t._vS[e].value+(t._vE[e].value-t._vS[e].value)*r+t._vE[e].unit}:"borderTopRightRadius"===r?e._r[r]=function(t,e,r){t._el.style[T]=t._vS[e].value+(t._vE[e].value-t._vS[e].value)*r+t._vE[e].unit}:"borderBottomLeftRadius"===r?e._r[r]=function(t,e,r){t._el.style[S]=t._vS[e].value+(t._vE[e].value-t._vS[e].value)*r+t._vE[e].unit}:"borderBottomRightRadius"===r&&(e._r[r]=function(t,e,r){t._el.style[b]=t._vS[e].value+(t._vE[e].value-t._vS[e].value)*r+t._vE[e].unit}):e._r[r]=function(t,e,r){t._el.style[e]=t._vS[e].value+(t._vE[e].value-t._vS[e].value)*r+t._vE[e].unit}}},e.prP=function(t,r){var n={},i=r===!0?Y:q,a=r===!0?Z:X,s=r===!0?Q:z;a={},i={};for(var o in t)if(-1!==F.indexOf(o)){if("translate"!==o&&/translate/.test(o)){var u=["X","Y","Z"],l=0;for(l;3>l;l++){var v=u[l];/3d/.test(o)?a["translate"+v]=e.pp("translate"+v,t[o][l]):a["translate"+v]="translate"+v in t?e.pp("translate"+v,t["translate"+v]):{value:0,unit:"px"}}i.translate=a}else if("rotate"!==o&&/rotate|skew/.test(o)){var f=/rotate/.test(o)?"rotate":"skew",p=["X","Y","Z"],c=0,d={},h={},s="rotate"===f?d:h;for(c;3>c;c++){var _=p[c];void 0!==t[f+_]&&"skewZ"!==o&&(s[f+_]=e.pp(f+_,t[f+_]))}i[f]=s}else("translate"===o||"rotate"===o||"scale"===o)&&(i[o]=e.pp(o,t[o]));n.transform=i}else-1===F.indexOf(o)&&(n[o]=e.pp(o,t[o]));return n},e.pp=function(t,r){if(-1!==F.indexOf(t)){var n,i=t.replace(/X|Y|Z/,"");if("translate3d"===t)return n=r.split(","),{translateX:{value:e.truD(n[0]).v,unit:e.truD(n[0]).u},translateY:{value:e.truD(n[1]).v,unit:e.truD(n[1]).u},translateZ:{value:e.truD(n[2]).v,unit:e.truD(n[2]).u}};if("translate"!==t&&"translate"===i)return{value:e.truD(r).v,unit:e.truD(r).u||"px"};if("rotate"!==t&&("skew"===i||"rotate"===i)&&"skewZ"!==t)return{value:e.truD(r).v,unit:e.truD(r,t).u||"deg"};if("translate"===t){n="string"==typeof r?r.split(","):r;var a={};return n instanceof Array?(a.x={value:e.truD(n[0]).v,unit:e.truD(n[0]).u},a.y={value:e.truD(n[1]).v,unit:e.truD(n[1]).u}):(a.x={value:e.truD(n).v,unit:e.truD(n).u},a.y={value:0,unit:"px"}),a}if("rotate"===t){var s={};return s.z={value:parseInt(r,10),unit:e.truD(r,t).u||"deg"},s}if("scale"===t)return{value:parseFloat(r,10)}}if(-1!==B.indexOf(t)||-1!==M.indexOf(t))return{value:e.truD(r).v,unit:e.truD(r).u};if(-1!==R.indexOf(t))return{value:parseFloat(r,10)};if(-1!==C.indexOf(t))return{value:parseFloat(r,10)};if(-1!==I.indexOf(t)){if(r instanceof Array)return[e.truD(r[0]),e.truD(r[1]),e.truD(r[2]),e.truD(r[3])];var o;return/rect/.test(r)?o=r.replace(/rect|\(|\)/g,"").split(/\s|\,/):/auto|none|initial/.test(r)&&(o=W[t]),[e.truD(o[0]),e.truD(o[1]),e.truD(o[2]),e.truD(o[3])]}if(-1!==x.indexOf(t))return{value:e.truC(r)};if(-1!==k.indexOf(t)){if(r instanceof Array)return{x:e.truD(r[0])||{v:50,u:"%"},y:e.truD(r[1])||{v:50,u:"%"}};var u=r.replace(/top|left/g,0).replace(/right|bottom/g,100).replace(/center|middle/,50).split(/\s|\,/g),l=e.truD(u[0]),v=e.truD(u[1]);return{x:l,y:v}}if(-1!==D.indexOf(t)){var f=e.truD(r);return{value:f.v,unit:f.u}}},e.truD=function(t,e){function r(){var r,n=0;for(n;a>n;n++)"string"==typeof t&&-1!==t.indexOf(i[n])&&(r=i[n]);return r=void 0!==r?r:e?"deg":"px"}var n=parseInt(t)||0,i=["px","%","deg","rad","em","rem","vh","vw"],a=i.length,s=r();return{v:n,u:s}},e.preventScroll=function(t){var e=document.body.getAttribute("data-tweening");e&&"scroll"===e&&t.preventDefault()},e.truC=function(t){var r,n;return/rgb|rgba/.test(t)?(r=t.replace(/[^\d,]/g,"").split(","),n=r[3]?r[3]:null,n?{r:parseInt(r[0]),g:parseInt(r[1]),b:parseInt(r[2]),a:parseFloat(n)}:{r:parseInt(r[0]),g:parseInt(r[1]),b:parseInt(r[2])}):/#/.test(t)?{r:e.htr(t).r,g:e.htr(t).g,b:e.htr(t).b}:/transparent|none|initial|inherit/.test(t)?{r:0,g:0,b:0,a:0}:void 0},e.rth=function(t,e,r){return"#"+((1<<24)+(t<<16)+(e<<8)+r).toString(16).slice(1)},e.htr=function(t){var e=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;t=t.replace(e,function(t,e,r,n){return e+e+r+r+n+n});var r=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return r?{r:parseInt(r[1],16),g:parseInt(r[2],16),b:parseInt(r[3],16)}:null},e.pe=function(t){if("function"==typeof t)return t;if("string"==typeof t){if(/easing|linear/.test(t))return e.Easing[t];if(/bezier/.test(t)){var r=t.replace(/bezier|\s|\(|\)/g,"").split(","),n=0,i=r.length;for(n;i>n;n++)r[n]=parseFloat(r[n]);return e.Ease.Bezier(r[0],r[1],r[2],r[3])}return/physics/.test(t)?e.Physics[t]():e.Ease[t]()}};var K=e.Easing={};K.linear=function(t){return t};var U=Math.PI,G=2*Math.PI,J=Math.PI/2,V=.1,tt=.4;K.easingSinusoidalIn=function(t){return-Math.cos(t*J)+1},K.easingSinusoidalOut=function(t){return Math.sin(t*J)},K.easingSinusoidalInOut=function(t){return-.5*(Math.cos(U*t)-1)},K.easingQuadraticIn=function(t){return t*t},K.easingQuadraticOut=function(t){return t*(2-t)},K.easingQuadraticInOut=function(t){return.5>t?2*t*t:-1+(4-2*t)*t},K.easingCubicIn=function(t){return t*t*t},K.easingCubicOut=function(t){return--t*t*t+1},K.easingCubicInOut=function(t){return.5>t?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1},K.easingQuarticIn=function(t){return t*t*t*t},K.easingQuarticOut=function(t){return 1- --t*t*t*t},K.easingQuarticInOut=function(t){return.5>t?8*t*t*t*t:1-8*--t*t*t*t},K.easingQuinticIn=function(t){return t*t*t*t*t},K.easingQuinticOut=function(t){return 1+--t*t*t*t*t},K.easingQuinticInOut=function(t){return.5>t?16*t*t*t*t*t:1+16*--t*t*t*t*t},K.easingCircularIn=function(t){return-(Math.sqrt(1-t*t)-1)},K.easingCircularOut=function(t){return Math.sqrt(1-(t-=1)*t)},K.easingCircularInOut=function(t){return(t*=2)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)},K.easingExponentialIn=function(t){return Math.pow(2,10*(t-1))-.001},K.easingExponentialOut=function(t){return 1-Math.pow(2,-10*t)},K.easingExponentialInOut=function(t){return(t*=2)<1?.5*Math.pow(2,10*(t-1)):.5*(2-Math.pow(2,-10*(t-1)))},K.easingBackIn=function(t){var e=1.70158;return t*t*((e+1)*t-e)},K.easingBackOut=function(t){var e=1.70158;return--t*t*((e+1)*t+e)+1},K.easingBackInOut=function(t){var e=2.5949095;return(t*=2)<1?.5*(t*t*((e+1)*t-e)):.5*((t-=2)*t*((e+1)*t+e)+2)},K.easingElasticIn=function(t){var e;return 0===t?0:1===t?1:(!V||1>V?(V=1,e=tt/4):e=tt*Math.asin(1/V)/G,-(V*Math.pow(2,10*(t-=1))*Math.sin((t-e)*G/tt)))},K.easingElasticOut=function(t){var e;return 0===t?0:1===t?1:(!V||1>V?(V=1,e=tt/4):e=tt*Math.asin(1/V)/G,V*Math.pow(2,-10*t)*Math.sin((t-e)*G/tt)+1)},K.easingElasticInOut=function(t){var e;return 0===t?0:1===t?1:(!V||1>V?(V=1,e=tt/4):e=tt*Math.asin(1/V)/G,(t*=2)<1?-.5*(V*Math.pow(2,10*(t-=1))*Math.sin((t-e)*G/tt)):V*Math.pow(2,-10*(t-=1))*Math.sin((t-e)*G/tt)*.5+1)},K.easingBounceIn=function(t){return 1-K.easingBounceOut(1-t)},K.easingBounceOut=function(t){return 1/2.75>t?7.5625*t*t:2/2.75>t?7.5625*(t-=1.5/2.75)*t+.75:2.5/2.75>t?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},K.easingBounceInOut=function(t){return.5>t?.5*K.easingBounceIn(2*t):.5*K.easingBounceOut(2*t-1)+.5},e.Tween=function(t,r,n,i){this._el=t,this._dr=i&&i.duration||700,this._r=i&&i.repeat||0,this._vSR={},this._vS=r,this._vE=n,this._y=i&&i.yoyo||!1,this.playing=!1,this.reversed=!1,this._rD=i&&i.repeatDelay||0,this._dl=i&&i.delay||0,this._sT=null,this.paused=!1,this._pST=null,this._to=i.transformOrigin,this._pp=i.perspective,this._ppo=i.perspectiveOrigin,this._ppp=i.parentPerspective,this._pppo=i.parentPerspectiveOrigin,this._rpr=i.rpr||!1,this._hex=i.keepHex||!1,this._e=i&&i.easing?e.pe(i.easing):e.Easing.linear,this._cT=[],this._sC=i&&i.start||null,this._sCF=!1,this._uC=i&&i.update||null,this._cC=i&&i.complete||null,this._pC=i&&i.pause||null,this._rC=i&&i.play||null,this._stC=i&&i.stop||null,this.repeat=this._r,e._queue(this)};var et=e.Tween.prototype;et.start=function(t){this.scrollIn();var i={};if(e.perspective(this._el,this),this._rpr){i=this.prS(),this._vS={},this._vS=e.prP(i,!1);for(var a in this._vS)if("transform"===a&&a in this._vE)for(var s in this._vS[a]){s in this._vE[a]||(this._vE[a][s]={});for(var o in this._vS[a][s])if(void 0!==this._vS[a][s][o].value){o in this._vE[a][s]||(this._vE[a][s][o]={});for(var u in this._vS[a][s][o])u in this._vE[a][s][o]||(this._vE[a][s][o][u]=this._vS[a][s][o][u])}if("value"in this._vS[a][s]&&!("value"in this._vE[a][s]))for(var l in this._vS[a][s])l in this._vE[a][s]||(this._vE[a][s][l]=this._vS[a][s][l])}}for(var v in this._vE)this._vSR[v]=this._vS[v];return this._sCF||(this._sC&&this._sC.call(),this._sCF=!0),r.push(this),this.playing=!0,this.paused=!1,this._sCF=!1,this._sT=t||window.performance.now(),this._sT+=this._dl,n||e._t(),this},et.stop=function(){return!this.paused&&this.playing&&(e.remove(this),this.playing=!1,this.paused=!1,this.scrollOut(),null!==this._stC&&this._stC.call(),this.stopChainedTweens(),this.close()),this},et.pause=function(){return!this.paused&&this.playing&&(e.remove(this),this.paused=!0,this._pST=window.performance.now(),null!==this._pC&&this._pC.call()),this},et.play=et.resume=function(){return this.paused&&this.playing&&(this.paused=!1,null!==this._rC&&this._rC.call(),this._sT+=window.performance.now()-this._pST,e.add(this),n||e._t()),this},et.reverse=function(){if(this._y)for(var t in this._vE){var e=this._vSR[t];this._vSR[t]=this._vE[t],this._vE[t]=e,this._vS[t]=this._vSR[t]}},et.chain=function(){return this._cT=arguments,this},et.stopChainedTweens=function(){var t=0,e=this._cT.length;for(t;e>t;t++)this._cT[t].stop()},et.scrollOut=function(){("scroll"in this._vE||"scrollTop"in this._vE)&&(this.removeListeners(),document.body.removeAttribute("data-tweening"))},et.scrollIn=function(){("scroll"in this._vE||"scrollTop"in this._vE)&&(document.body.getAttribute("data-tweening")||(document.body.setAttribute("data-tweening","scroll"),this.addListeners()))},et.addListeners=function(){document.addEventListener(l,e.preventScroll,!1)},et.removeListeners=function(){document.removeEventListener(l,e.preventScroll,!1)},et.prS=function(){var t={},e=this._el,r=this._vS,n=this.gIS("transform"),i=["rotate","skew"],a=["X","Y","Z"];for(var s in r)if(-1!==F.indexOf(s)){var o="rotate"===s||"translate"===s||"scale"===s;if(/translate/.test(s)&&"translate"!==s)t.translate3d=n.translate3d||W[s];else if(o)t[s]=n[s]||W[s];else if(!o&&/rotate|skew/.test(s))for(var u=0;2>u;u++)for(var l=0;3>l;l++){var v=i[u]+a[l];-1!==F.indexOf(v)&&v in r&&(t[v]=n[v]||W[v])}}else if(-1===C.indexOf(s))if("opacity"===s&&d){var f=this.gCS("filter");t.opacity="number"==typeof f?f:W.opacity}else t[s]=this.gCS(s)||W[s];else t[s]=null===e||void 0===e?window.pageYOffset||p.scrollTop:e.scrollTop;for(var s in n)-1===F.indexOf(s)||s in r||(t[s]=n[s]||W[s]);return t},et.gIS=function(t){if(this._el){var e=this._el,r=e.style.cssText,n={},i=r.replace(/\s/g,"").split(";"),a=0,s=i.length;for(a;s>a;a++)if(/transform/.test(i[a])){var o=i[a].split(":")[1].split(")"),u=0,l=o.length;for(u;l>u;u++){var v=o[u].split("(");""!==v[0]&&F.indexOf(v)&&(n[v[0]]=/translate3d/.test(v[0])?v[1].split(","):v[1])}}return n}},et.gCS=function(t){var e=this._el,r=window.getComputedStyle(e)||e.currentStyle,n=!d&&s&&/transform|Radius/.test(t)?"-"+i.toLowerCase()+"-"+t:t,a=s&&"transform"===t||s&&-1!==D.indexOf(t)?r[n]:r[t];if("transform"!==t&&n in r){if(a){if("filter"===n){var o=parseInt(a.split("=")[1].replace(")","")),u=parseFloat(o/100);return u}return a}return W[t]}},et.close=function(){var t=this;setTimeout(function(){var n=r.indexOf(t);n===r.length-1&&e.s(),t.repeat>0&&(t._r=t.repeat),t._y&&t.reversed===!0&&(t.reverse(),t.reversed=!1),t.playing=!1},61)},e.TweensAT=function(t,r,n){this.tweens=[];var i,a=t.length,s=[];for(i=0;a>i;i++)s[i]=n||{},n.delay=n.delay||0,s[i].delay=i>0?n.delay+(n.offset||0):n.delay,this.tweens.push(e.to(t[i],r,s[i]))},e.TweensFT=function(t,r,n,i){this.tweens=[];var a,s=t.length,o=[];for(a=0;s>a;a++)o[a]=i||{},i.delay=i.delay||0,o[a].delay=a>0?i.delay+(i.offset||0):i.delay,this.tweens.push(e.fromTo(t[a],r,n,o[a]))};var rt=e.TweensAT.prototype=e.TweensFT.prototype;return rt.start=function(t){t=t||window.performance.now();var e,r=this.tweens.length;for(e=0;r>e;e++)this.tweens[e].start(t);return this},rt.stop=function(){for(var t=0;t 1 ? this : this[0], method = this.length > 1 ? 'allFromTo' : 'fromTo'; + return KUTE[method](el,from,to,ops); }; - return $K; -}); + + $.fn.to = function(to,ops) { + var el = this.length > 1 ? this : this[0], method = this.length > 1 ? 'allTo' : 'to'; + return KUTE[method](el,to,ops); + }; + + return this; +}); \ No newline at end of file diff --git a/kute-matrix.js b/kute-matrix.js new file mode 100644 index 0000000..91a9f2b --- /dev/null +++ b/kute-matrix.js @@ -0,0 +1,509 @@ +/* KUTE.js - The Light Tweening Engine + * package - Matrix Transform Plugin + * desc - adds the ability to animate transform with matrix / matrix3d + * by dnp_theme + * Licensed under MIT-License + */ + + +(function(factory){ + if (typeof define === 'function' && define.amd) { + define(["./kute.js"], function(KUTE){ factory(KUTE); return KUTE; }); + } else if(typeof module == "object" && typeof require == "function") { + var KUTE = require("./kute.js"); + // Export the modified one. Not really required, but convenient. + module.exports = factory(KUTE); + } else if(typeof window.KUTE != "undefined") { + // window.KUTE.Matrix = window.KUTE.Matrix || factory(KUTE); + factory(KUTE); + } else { + throw new Error("Matrix Plugin require KUTE.js.") + } +})(function(KUTE){ + 'use strict'; + var K = window.KUTE, _pf = K.getPrefix(), + _pfT = (!('transform' in document.body.style)) ? true : false, // is prefix required for transform + _tr = _pfT ? _pf + 'Transform' : 'transform', + _3d = ['rotateX', 'rotateY','translateZ', 'perspective', 'rotate3d', 'scale3d', 'translate3d'], // transform properties that require perspective + _tf = ['translate3d', 'translateX', 'translateY', 'translateZ', 'rotate', 'translate', 'rotateX', 'rotateY', 'rotateZ', 'skewX', 'skewY', 'scale']; // transform + + + /** + * CSSMatrix Shim + * @constructor + */ + // CSS Matrix as implemented by @arian + // https://github.com/arian/M/blob/master/CSSMatrix.js + var CSSMatrix = function(){ + var a = [].slice.call(arguments), + m = this; + // if (a.length) for (var i = a.length; i--;){ + // if (Math.abs(a[i]) < CSSMatrix.SMALL_NUMBER) a[i] = 0; + // } + m.setIdentity(); + if (a.length == 16){ + m.m11 = m.a = a[0]; m.m12 = m.b = a[1]; m.m13 = a[2]; m.m14 = a[3]; + m.m21 = m.c = a[4]; m.m22 = m.d = a[5]; m.m23 = a[6]; m.m24 = a[7]; + m.m31 = a[8]; m.m32 = a[9]; m.m33 = a[10]; m.m34 = a[11]; + m.m41 = m.e = a[12]; m.m42 = m.f = a[13]; m.m43 = a[14]; m.m44 = a[15]; + } else if (a.length == 6) { + this.affine = true; + m.m11 = m.a = a[0]; m.m12 = m.b = a[1]; m.m14 = m.e = a[4]; + m.m21 = m.c = a[2]; m.m22 = m.d = a[3]; m.m24 = m.f = a[5]; + } else if (a.length === 1 && typeof a[0] == 'string') { + m.setMatrixValue(a[0]); + } else if (a.length > 0) { + throw new TypeError('Invalid Matrix Value'); + } + }; + + // decimal values in WebKitCSSMatrix.prototype.toString are truncated to 6 digits + CSSMatrix.SMALL_NUMBER = 1e-20; + + // Transformations + + // http://en.wikipedia.org/wiki/Rotation_matrix + CSSMatrix.Rotate = function(rx, ry, rz){ + rx *= Math.PI / 180; + ry *= Math.PI / 180; + rz *= Math.PI / 180; + // minus sin() because of right-handed system + var cosx = Math.cos(rx), sinx = - Math.sin(rx); + var cosy = Math.cos(ry), siny = - Math.sin(ry); + var cosz = Math.cos(rz), sinz = - Math.sin(rz); + var m = new CSSMatrix(); + + m.m11 = m.a = cosy * cosz; + m.m12 = m.b = - cosy * sinz; + m.m13 = siny; + + m.m21 = m.c = sinx * siny * cosz + cosx * sinz; + m.m22 = m.d = cosx * cosz - sinx * siny * sinz; + m.m23 = - sinx * cosy; + + m.m31 = sinx * sinz - cosx * siny * cosz; + m.m32 = sinx * cosz + cosx * siny * sinz; + m.m33 = cosx * cosy; + + return m; + }; + + CSSMatrix.RotateAxisAngle = function(x, y, z, angle){ + angle *= Math.PI / 360; + + var sinA = Math.sin(angle), cosA = Math.cos(angle), sinA2 = sinA * sinA; + var length = Math.sqrt(x * x + y * y + z * z); + + if (length === 0){ + // bad vector length, use something reasonable + x = 0; + y = 0; + z = 1; + } else { + x /= length; + y /= length; + z /= length; + } + + var x2 = x * x, y2 = y * y, z2 = z * z; + + var m = new CSSMatrix(); + m.m11 = m.a = 1 - 2 * (y2 + z2) * sinA2; + m.m12 = m.b = 2 * (x * y * sinA2 + z * sinA * cosA); + m.m13 = 2 * (x * z * sinA2 - y * sinA * cosA); + m.m21 = m.c = 2 * (y * x * sinA2 - z * sinA * cosA); + m.m22 = m.d = 1 - 2 * (z2 + x2) * sinA2; + m.m23 = 2 * (y * z * sinA2 + x * sinA * cosA); + m.m31 = 2 * (z * x * sinA2 + y * sinA * cosA); + m.m32 = 2 * (z * y * sinA2 - x * sinA * cosA); + m.m33 = 1 - 2 * (x2 + y2) * sinA2; + m.m14 = m.m24 = m.m34 = 0; + m.m41 = m.e = m.m42 = m.f = m.m43 = 0; + m.m44 = 1; + + return m; + }; + + CSSMatrix.ScaleX = function(x){ + var m = new CSSMatrix(); + m.m11 = m.a = x; + return m; + }; + + CSSMatrix.ScaleY = function(y){ + var m = new CSSMatrix(); + m.m22 = m.d = y; + return m; + }; + + CSSMatrix.ScaleZ = function(z){ + var m = new CSSMatrix(); + m.m33 = z; + return m; + }; + + CSSMatrix.Scale = function(x, y, z){ + var m = new CSSMatrix(); + m.m11 = m.a = x; + m.m22 = m.d = y; + m.m33 = z; + return m; + }; + + CSSMatrix.SkewX = function(angle){ + angle *= Math.PI / 180; + var m = new CSSMatrix(); + m.m21 = m.c = Math.tan(angle); + return m; + }; + + CSSMatrix.SkewY = function(angle){ + angle *= Math.PI / 180; + var m = new CSSMatrix(); + m.m12 = m.b = Math.tan(angle); + return m; + }; + + CSSMatrix.Translate = function(x, y, z){ + var m = new CSSMatrix(); + m.m41 = m.e = x; + m.m42 = m.f = y; + m.m43 = z; + return m; + }; + + CSSMatrix.multiply = function(m1, m2){ + + var m11 = m2.m11 * m1.m11 + m2.m12 * m1.m21 + m2.m13 * m1.m31 + m2.m14 * m1.m41, + m12 = m2.m11 * m1.m12 + m2.m12 * m1.m22 + m2.m13 * m1.m32 + m2.m14 * m1.m42, + m13 = m2.m11 * m1.m13 + m2.m12 * m1.m23 + m2.m13 * m1.m33 + m2.m14 * m1.m43, + m14 = m2.m11 * m1.m14 + m2.m12 * m1.m24 + m2.m13 * m1.m34 + m2.m14 * m1.m44, + + m21 = m2.m21 * m1.m11 + m2.m22 * m1.m21 + m2.m23 * m1.m31 + m2.m24 * m1.m41, + m22 = m2.m21 * m1.m12 + m2.m22 * m1.m22 + m2.m23 * m1.m32 + m2.m24 * m1.m42, + m23 = m2.m21 * m1.m13 + m2.m22 * m1.m23 + m2.m23 * m1.m33 + m2.m24 * m1.m43, + m24 = m2.m21 * m1.m14 + m2.m22 * m1.m24 + m2.m23 * m1.m34 + m2.m24 * m1.m44, + + m31 = m2.m31 * m1.m11 + m2.m32 * m1.m21 + m2.m33 * m1.m31 + m2.m34 * m1.m41, + m32 = m2.m31 * m1.m12 + m2.m32 * m1.m22 + m2.m33 * m1.m32 + m2.m34 * m1.m42, + m33 = m2.m31 * m1.m13 + m2.m32 * m1.m23 + m2.m33 * m1.m33 + m2.m34 * m1.m43, + m34 = m2.m31 * m1.m14 + m2.m32 * m1.m24 + m2.m33 * m1.m34 + m2.m34 * m1.m44, + + m41 = m2.m41 * m1.m11 + m2.m42 * m1.m21 + m2.m43 * m1.m31 + m2.m44 * m1.m41, + m42 = m2.m41 * m1.m12 + m2.m42 * m1.m22 + m2.m43 * m1.m32 + m2.m44 * m1.m42, + m43 = m2.m41 * m1.m13 + m2.m42 * m1.m23 + m2.m43 * m1.m33 + m2.m44 * m1.m43, + m44 = m2.m41 * m1.m14 + m2.m42 * m1.m24 + m2.m43 * m1.m34 + m2.m44 * m1.m44; + + return new CSSMatrix( m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44 ); + }; + + // w3c defined methods + + /** + * The setMatrixValue method replaces the existing matrix with one computed + * from parsing the passed string as though it had been assigned to the + * transform property in a CSS style rule. + * @param {String} string The string to parse. + */ + CSSMatrix.prototype.setMatrixValue = function(string){ + string = String(string).trim(); + var m = this; + m.setIdentity(); + if (string == 'none') return m; + var type = string.slice(0, string.indexOf('(')), parts, i; + if (type == 'matrix3d'){ + parts = string.slice(9, -1).split(','); + for (i = parts.length; i--;) parts[i] = parseFloat(parts[i]); + m.m11 = m.a = parts[0]; m.m12 = m.b = parts[1]; m.m13 = parts[2]; m.m14 = parts[3]; + m.m21 = m.c = parts[4]; m.m22 = m.d = parts[5]; m.m23 = parts[6]; m.m24 = parts[7]; + m.m31 = parts[8]; m.m32 = parts[9]; m.m33 = parts[10]; m.m34 = parts[11]; + m.m41 = m.e = parts[12]; m.m42 = m.f = parts[13]; m.m43 = parts[14]; m.m44 = parts[15]; + } else if (type == 'matrix'){ + m.affine = true; + parts = string.slice(7, -1).split(','); + for (i = parts.length; i--;) parts[i] = parseFloat(parts[i]); + m.m11 = m.a = parts[0]; m.m12 = m.b = parts[2]; m.m41 = m.e = parts[4]; + m.m21 = m.c = parts[1]; m.m22 = m.d = parts[3]; m.m42 = m.f = parts[5]; + } else { + throw new TypeError('Invalid Matrix Value'); + } + return m; + }; + + /** + * The multiply method returns a new CSSMatrix which is the result of this + * matrix multiplied by the passed matrix, with the passed matrix to the right. + * This matrix is not modified. + * + * @param {CSSMatrix} m2 + * @return {CSSMatrix} The result matrix. + */ + CSSMatrix.prototype.multiply = function(m2){ + return CSSMatrix.multiply(this, m2); + }; + + /** + * The translate method returns a new matrix which is this matrix post + * multiplied by a translation matrix containing the passed values. If the z + * component is undefined, a 0 value is used in its place. This matrix is not + * modified. + * + * @param {number} x X component of the translation value. + * @param {number} y Y component of the translation value. + * @param {number=} z Z component of the translation value. + * @return {CSSMatrix} The result matrix + */ + CSSMatrix.prototype.translate = function(x, y, z){ + if (z == null) z = 0; + return CSSMatrix.multiply(this, CSSMatrix.Translate(x, y, z)); + }; + + /** + * The scale method returns a new matrix which is this matrix post multiplied by + * a scale matrix containing the passed values. If the z component is undefined, + * a 1 value is used in its place. If the y component is undefined, the x + * component value is used in its place. This matrix is not modified. + * + * @param {number} x The X component of the scale value. + * @param {number=} y The Y component of the scale value. + * @param {number=} z The Z component of the scale value. + * @return {CSSMatrix} The result matrix + */ + CSSMatrix.prototype.scale = function(x, y, z){ + if (y == null) y = x; + if (z == null) z = 1; + return CSSMatrix.multiply(this, CSSMatrix.Scale(x, y, z)); + }; + + /** + * The rotate method returns a new matrix which is this matrix post multiplied + * by each of 3 rotation matrices about the major axes, first X, then Y, then Z. + * If the y and z components are undefined, the x value is used to rotate the + * object about the z axis, as though the vector (0,0,x) were passed. All + * rotation values are in degrees. This matrix is not modified. + * + * @param {number} rx The X component of the rotation value, or the Z component if the rotY and rotZ parameters are undefined. + * @param {number=} ry The (optional) Y component of the rotation value. + * @param {number=} rz The (optional) Z component of the rotation value. + * @return {CSSMatrix} The result matrix + */ + CSSMatrix.prototype.rotate = function(rx, ry, rz){ + if (ry == null) ry = rx; + if (rz == null) rz = rx; + return CSSMatrix.multiply(this, CSSMatrix.Rotate(rx, ry, rz)); + }; + + /** + * The rotateAxisAngle method returns a new matrix which is this matrix post + * multiplied by a rotation matrix with the given axis and angle. The right-hand + * rule is used to determine the direction of rotation. All rotation values are + * in degrees. This matrix is not modified. + * + * @param {number} x The X component of the axis vector. + * @param {number=} y The Y component of the axis vector. + * @param {number=} z The Z component of the axis vector. + * @param {number} angle The angle of rotation about the axis vector, in degrees. + * @return {CSSMatrix} The result matrix + */ + CSSMatrix.prototype.rotateAxisAngle = function(x, y, z, angle){ + if (y == null) y = x; + if (z == null) z = x; + return CSSMatrix.multiply(this, CSSMatrix.RotateAxisAngle(x, y, z, angle)); + }; + + // Defined in WebKitCSSMatrix, but not in the w3c draft + + /** + * Specifies a skew transformation along the x-axis by the given angle. + * + * @param {number} angle The angle amount in degrees to skew. + * @return {CSSMatrix} The result matrix + */ + CSSMatrix.prototype.skewX = function(angle){ + return CSSMatrix.multiply(this, CSSMatrix.SkewX(angle)); + }; + + /** + * Specifies a skew transformation along the x-axis by the given angle. + * + * @param {number} angle The angle amount in degrees to skew. + * @return {CSSMatrix} The result matrix + */ + CSSMatrix.prototype.skewY = function(angle){ + return CSSMatrix.multiply(this, CSSMatrix.SkewY(angle)); + }; + + /** + * Returns a string representation of the matrix. + * @return {string} + */ + CSSMatrix.prototype.toString = function(){ + var m = this; + + if (this.affine){ + return 'matrix(' + [ + m.a, m.b, + m.c, m.d, + m.e, m.f + ].join(', ') + ')'; + } + // note: the elements here are transposed + return 'matrix3d(' + [ + m.m11, m.m12, m.m13, m.m14, + m.m21, m.m22, m.m23, m.m24, + m.m31, m.m32, m.m33, m.m34, + m.m41, m.m42, m.m43, m.m44 + ].join(', ') + ')'; + }; + + + // Additional methods + + /** + * Set the current matrix to the identity form + * + * @return {CSSMatrix} this matrix + */ + CSSMatrix.prototype.setIdentity = function(){ + var m = this; + m.m11 = m.a = 1; m.m12 = m.b = 0; m.m13 = 0; m.m14 = 0; + m.m21 = m.c = 0; m.m22 = m.d = 1; m.m23 = 0; m.m24 = 0; + m.m31 = 0; m.m32 = 0; m.m33 = 1; m.m34 = 0; + m.m41 = m.e = 0; m.m42 = m.f = 0; m.m43 = 0; m.m44 = 1; + return this; + }; + + /** + * Transform a tuple (3d point) with this CSSMatrix + * + * @param {Tuple} an object with x, y, z and w properties + * @return {Tuple} the passed tuple + */ + CSSMatrix.prototype.transform = function(t /* tuple */ ){ + var m = this; + + var x = m.m11 * t.x + m.m12 * t.y + m.m13 * t.z + m.m14 * t.w, + y = m.m21 * t.x + m.m22 * t.y + m.m23 * t.z + m.m24 * t.w, + z = m.m31 * t.x + m.m32 * t.y + m.m33 * t.z + m.m34 * t.w, + w = m.m41 * t.x + m.m42 * t.y + m.m43 * t.z + m.m44 * t.w; + + t.x = x / w; + t.y = y / w; + t.z = z / w; + + return t; + }; + + // CSSMatrix.prototype.toFullString = function(){ + // var m = this; + // return [ + // [m.m11, m.m12, m.m13, m.m14].join(', '), + // [m.m21, m.m22, m.m23, m.m24].join(', '), + // [m.m31, m.m32, m.m33, m.m34].join(', '), + // [m.m41, m.m42, m.m43, m.m44].join(', ') + // ].join('\n'); + // }; + + CSSMatrix.Perspective = function(d){ + var m = new CSSMatrix(); + m.m34 = -1/d; + return m; + }; + + + + /** + * The perspective method returns a new matrix which is this matrix post + * multiplied by a perspective matrix containing the passed values. If the + * y and z components are undefined, a 0 value is used in its place. + * + * @param {number} x X component of the perspective value. + * @param {number} y Y component of the perspective value. + * @param {number=} z Z component of the perspective value. + * @return {M} The result matrix + */ + CSSMatrix.prototype.perspective = function(d){ + return CSSMatrix.multiply(this, CSSMatrix.Perspective(d)); + }; + + CSSMatrix.toMat4 = function(out, a) { + if (!out) + out = new Array(16) + + out[0] = a[0] + out[1] = a[1] + out[2] = 0 + out[3] = 0 + out[4] = a[2] + out[5] = a[3] + out[6] = 0 + out[7] = 0 + out[8] = 0 + out[9] = 0 + out[10] = 1 + out[11] = 0 + out[12] = a[4] + out[13] = a[5] + out[14] = 0 + out[15] = 1 + return out + } + + CSSMatrix.prototype.toArray = function(p){ + if (p === 'matrix'){ + return [this.a, this.b, this.c, this.d, this.e, this.f]; + } else { + return [this.m11, this.m12, this.m13, this.m14, this.m21, this.m22, this.m23, this.m24, this.m31, this.m32, this.m33, this.m34, this.m41, this.m42, this.m43, this.m44]; + } + } + + K.pp['matrix'] = function(p,v,l){ + if ( !('matrix' in K.dom) ) { + K.dom['matrix'] = function(w,p,v) { + var m = [], i, l = w._vS[p].length, t = l===6 ? 'matrix' : 'matrix3d'; + for (i=0; i 0.001) { - _kpg.L = curve.b - curve.a; + L = curve.b - curve.a; curve = { a: curve.b, - b: curve.b + _kpg.L * bounciness, + b: curve.b + L * bounciness, H: curve.H * bounciness * bounciness }; } @@ -128,7 +113,7 @@ (function() { var L2, b, curve, _results; - b = Math.sqrt(2 / (gravity * _kpg.L * _kpg.L)); + b = Math.sqrt(2 / (gravity * L * L)); curve = { a: -b, b: b, @@ -139,7 +124,7 @@ curve.b = curve.b * 2; } curves.push(curve); - L2 = _kpg.L; + L2 = L; _results = []; while (curve.b < 1 && curve.H > 0.001) { L2 = curve.b - curve.a; @@ -152,7 +137,7 @@ } return _results; })(); - _kpg.fn = function(t) { + return function(t) { var curve, i, v; i = 0; curve = curves[i]; @@ -166,17 +151,13 @@ if (!curve) { v = initialForce ? 0 : 1; } else { - v = _kpg.getPointInCurve(curve.a, curve.b, curve.H, t, options, _kpg.L); + v = _kpg.getPointInCurve(curve.a, curve.b, curve.H, t, options, L); } return v; }; - - return _kpg.fn; }; - var _kpg = P.gravity.prototype; - _kpg.L = {}; - _kpg.fn = {}; + var _kpg = g.gravity.prototype; _kpg.getPointInCurve = function(a, b, H, t, o, L) { var c, t2; L = b - a; @@ -189,15 +170,14 @@ }; //throw up and pull down by gravity - P.forceWithGravity = function(o) { + g.forceWithGravity = function(o) { var ops = o || {}; ops.initialForce = true; - return P.gravity(ops); + return g.gravity(ops); }; - // multi point bezier - P.bezier = function(options) { + g.BezierMultiPoint = function(options) { options = options || {}; var points = options.points, returnsToSelf = false, Bs = []; @@ -215,7 +195,7 @@ return Bs; })(); - _kpb.run = function(t) { + return function(t) { if (t === 0) { return 0; } else if (t === 1) { @@ -224,12 +204,9 @@ return _kpb.yForX(t, Bs, returnsToSelf); } }; - return _kpb.run; }; - var _kpb = P.bezier.prototype; - _kpb.B2 = {}; - _kpb.run = {}; + var _kpb = g.BezierMultiPoint.prototype; _kpb.fn = function(pointA, pointB, Bs) { var B2 = function(t) { @@ -277,46 +254,44 @@ return B(percent).y; }; - P.physicsInOut = function(options) { - var friction; - options = options || {}; - friction = options.friction|| 500; - return P.bezier({ points: [ { x: 0, y: 0, cp: [ { x: 0.92 - (friction / 1000), y: 0 } ] }, { x: 1, y: 1, cp: [ { x: 0.08 + (friction / 1000), y: 1 } ] } ] }); + // export predefined BezierMultiPoint functions to window + g.Physics = { + physicsInOut : function(options) { + var friction; + options = options || {}; + friction = options.friction|| 200; + return g.BezierMultiPoint({ points: [ { x: 0, y: 0, cp: [ { x: 0.92 - (friction / 1000), y: 0 } ] }, { x: 1, y: 1, cp: [ { x: 0.08 + (friction / 1000), y: 1 } ] } ] }); + }, + physicsIn : function(options) { + var friction; + options = options || {}; + friction = options.friction|| 200; + return g.BezierMultiPoint({ points: [ { x: 0, y: 0, cp: [ { x: 0.92 - (friction / 1000), y: 0 } ] }, { x: 1, y: 1, cp: [ { x: 1, y: 1 } ] } ] }); + }, + physicsOut : function(options) { + var friction; + options = options || {}; + friction = options.friction|| 200; + return g.BezierMultiPoint({ points: [ { x: 0, y: 0, cp: [ { x: 0, y: 0 } ] }, { x: 1, y: 1, cp: [ { x: 0.08 + (friction / 1000), y: 1 } ] }] }); + }, + physicsBackOut : function(options) { + var friction; + options = options || {}; + friction = options.friction|| 200; + return g.BezierMultiPoint({ points: [{x:0,y:0,cp:[{x:0,y:0}]},{x:1,y:1,cp:[{x:0.735+(friction/1000),y:1.3}]}] }); + }, + physicsBackIn : function(options) { + var friction; + options = options || {}; + friction = options.friction|| 200; + return g.BezierMultiPoint({ points: [{x:0,y:0,cp:[{x:0.28-(friction / 1000),y:-0.6}]},{x:1,y:1,cp:[{x:1,y:1}]}] }); + }, + physicsBackInOut : function(options) { + var friction; + options = options || {}; + friction = options.friction|| 200; + return g.BezierMultiPoint({ points: [{x:0,y:0,cp:[{x:0.68-(friction / 1000),y:-0.55}]},{x:1,y:1,cp:[{x:0.265+(friction / 1000),y:1.45}]}] }); + } }; - P.physicsIn = function(options) { - var friction; - options = options || {}; - friction = options.friction|| 500; - return P.bezier({ points: [ { x: 0, y: 0, cp: [ { x: 0.92 - (friction / 1000), y: 0 } ] }, { x: 1, y: 1, cp: [ { x: 1, y: 1 } ] } ] }); - }; - - P.physicsOut = function(options) { - var friction; - options = options || {}; - friction = options.friction|| 500; - return P.bezier({ points: [ { x: 0, y: 0, cp: [ { x: 0, y: 0 } ] }, { x: 1, y: 1, cp: [ { x: 0.08 + (friction / 1000), y: 1 } ] }] }); - }; - - P.physicsBackOut = function(options) { - var friction; - options = options || {}; - friction = options.friction|| 500; - return P.bezier({ points: [{"x":0,"y":0,"cp":[{"x":0,"y":0}]},{"x":1,"y":1,"cp":[{"x":0.735+(friction/1000),"y":1.3}]}] }); - }; - - P.physicsBackIn = function(options) { - var friction; - options = options || {}; - friction = options.friction|| 500; - return P.bezier({ points: [{"x":0,"y":0,"cp":[{"x":0.28-(friction / 1000),"y":-0.6}]},{"x":1,"y":1,"cp":[{"x":1,"y":1}]}] }); - }; - - P.physicsBackInOut = function(options) { - var friction; - options = options || {}; - friction = options.friction|| 500; - return P.bezier({ points: [{"x":0,"y":0,"cp":[{"x":0.68-(friction / 1000),"y":-0.55}]},{"x":1,"y":1,"cp":[{"x":0.265+(friction / 1000),"y":1.45}]}] }); - }; - return P; }); diff --git a/kute-textticker.js b/kute-textticker.js new file mode 100644 index 0000000..59f57d6 --- /dev/null +++ b/kute-textticker.js @@ -0,0 +1,63 @@ +/*! + * TextTickerPlugin.js + * version 1.0.0 + * A string character tweening + * special for KUTE.js + * by @dalisoft (https://github.com/dalisoft) + * Licensed under MIT-License + */ +(function (factory) { + if (typeof define === 'function' && define.amd) { + define(["./kute.js"], function(KUTE){ factory(KUTE); return KUTE; }); + } else if(typeof module == "object" && typeof require == "function") { + var KUTE = require("./kute.js"); + module.exports = factory(KUTE); + } else if ( typeof window.KUTE !== 'undefined' ) { + factory(window.KUTE); + } else { + throw new Error("TextTicker-Plugin requires KUTE.js."); + } +}( function (KUTE) { + + function TextTicker( element, _a ) { + + return function ( _b ) { + + var len = Math.max(_a.length, _b.length); + + return function( value ) { + + var substr = Math.floor( Math.min( value * len, len ) ); + + element.innerHTML = _b.substring( 0, substr ) + _a.substr( substr ); + + }; + + } + +} + +KUTE.pp['text'] = function( prop, value, element ){ + + if ( typeof value === "string" ) { + + var t = TextTicker( element, element.innerHTML )( value ); + + if ( !( 'text' in KUTE.dom ) ) { + + KUTE.dom['text'] = function (elem, prop, value) { + + t(value); + } + + } + + } + + return this; + +} + + return this; + +})); diff --git a/kute.js b/kute.js deleted file mode 100644 index 1c50ef7..0000000 --- a/kute.js +++ /dev/null @@ -1,902 +0,0 @@ -/* KUTE.js - The Light Tweening Engine - * by dnp_theme - * Licensed under MIT-License - */ - -(function (factory) { - if (typeof define === 'function' && define.amd) { - define([], factory); // AMD. Register as an anonymous module. - } else if (typeof exports == 'object') { - module.exports = factory(); // Node, not strict CommonJS - } else { - // Browser globals - window.KUTE = window.KUTE || factory(); - } -}( function () { - "use strict"; - var K = K || {}, _tws = [], _t = null, - _pf = getPrefix(), // prefix - _rafR = (!('requestAnimationFrame' in window)) ? true : false, // is prefix required for requestAnimationFrame - _pfT = (!('transform' in document.getElementsByTagName('div')[0].style)) ? true : false, // is prefix required for transform - _pfB = (!('border-radius' in document.getElementsByTagName('div')[0].style)) ? true : false, // is prefix required for border-radius - _tch = ('ontouchstart' in window || navigator.msMaxTouchPoints) || false, // support Touch? - _ev = _tch ? 'touchstart' : 'mousewheel', //event to prevent on scroll - - _bd = document.body, _htm = document.getElementsByTagName('HTML')[0], - _sct = (/webkit/i.test(navigator.userAgent) || document.compatMode == 'BackCompat' ? _bd : _htm), - - _isIE = (new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})").exec(navigator.userAgent) != null) ? parseFloat( RegExp.$1 ) : false, - _isIE8 = _isIE === 8, // check IE8/IE - - //assign preffix to DOM properties - _pfto = _pfT ? _pf + 'TransformOrigin' : 'transformOrigin', - _pfp = _pfT ? _pf + 'Perspective' : 'perspective', - _pfo = _pfT ? _pf + 'PerspectiveOrigin' : 'perspectiveOrigin', - _tr = _pfT ? _pf + 'Transform' : 'transform', - _br = _pfB ? _pf + 'BorderRadius' : 'borderRadius', - _brtl = _pfB ? _pf + 'BorderTopLeftRadius' : 'borderTopLeftRadius', - _brtr = _pfB ? _pf + 'BorderTopRightRadius' : 'borderTopRightRadius', - _brbl = _pfB ? _pf + 'BorderBottomLeftRadius' : 'borderBottomLeftRadius', - _brbr = _pfB ? _pf + 'BorderBottomRightRadius' : 'borderBottomRightRadius', - _raf = _rafR ? window[_pf + 'RequestAnimationFrame'] : window['requestAnimationFrame'], - _caf = _rafR ? (window[_pf + 'CancelAnimationFrame'] || window[_pf + 'CancelRequestAnimationFrame']) : window['cancelAnimationFrame'], - - //supported properties - _cls = ['color', 'backgroundColor', 'borderColor', 'borderTopColor', 'borderRightColor', 'borderBottomColor', 'borderLeftColor'], // colors 'hex', 'rgb', 'rgba' -- #fff / rgb(0,0,0) / rgba(0,0,0,0) - _sc = ['scrollTop', 'scroll'], //scroll, it has no default value, it's calculated on tween start - _clp = ['clip'], // clip - _op = ['opacity'], // opacity - _rd = ['borderRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomLeftRadius', 'borderBottomRightRadius'], // border radius px/any - _bm = ['top', 'left', 'right', 'bottom', - 'width', 'height', 'minWidth', 'minHeight', 'maxWidth', 'maxHeight', - 'padding', 'margin', 'paddingTop','paddingBottom', 'paddingLeft', 'paddingRight', 'marginTop','marginBottom', 'marginLeft', 'marginRight', - 'borderWidth', 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth'], // dimensions / box model - _tp = ['fontSize','lineHeight','letterSpacing'], // text properties - _bg = ['backgroundPosition'], // background position - _3d = ['rotateX', 'rotateY','translateZ'], // transform properties that require perspective - _tf = ['translate3d', 'translateX', 'translateY', 'translateZ', 'rotate', 'translate', 'rotateX', 'rotateY', 'rotateZ', 'skewX', 'skewY', 'scale'], // transform - _all = _cls.concat(_sc, _clp, _op, _rd, _bm, _tp, _bg, _tf), al = _all.length, - _tfS = {}, _tfE = {}, _tlS = {}, _tlE = {}, _rtS = {}, _rtE = {}, //internal temp - _d = _d || {}; //all properties default values - - //populate default values object - for ( var i=0; i< al; i++ ){ - var p = _all[i]; - if (_cls.indexOf(p) !== -1){ - _d[p] = 'rgba(0,0,0,0)'; // _d[p] = {r:0,g:0,b:0,a:1}; - } else if ( _rd.indexOf(p) !== -1 || _bm.indexOf(p) !== -1 || _tp.indexOf(p) !== -1) { - _d[p] = 0; - } else if ( _bg.indexOf(p) !== -1 ){ - _d[p] = [50,50]; - } else if ( p === 'clip' ){ - _d[p] = [0,0,0,0]; - } else if ( p === 'translate3d' ){ - _d[p] = [0,0,0]; - } else if ( p === 'translate' ){ - _d[p] = [0,0]; - } else if ( p === 'rotate' || /X|Y|Z/.test(p) ){ - _d[p] = 0; - } else if ( p === 'scale' || p === 'opacity' ){ - _d[p] = 1; - } - } - - // main methods - K.to = function (el, to, o) { - var _el = typeof el === 'object' ? el : document.querySelector(el), - _vS = to, _vE = K.prP(to, true); // we're gonna have to build _vS object at start - o = o || {}; o.rpr = true; - return new K.Tween(_el, _vS, _vE, o); - }; - - K.fromTo = function (el, f, to, o) { - var _el = typeof el === 'object' ? el : document.querySelector(el), - _vS = K.prP(f, false), _vE = K.prP(to, true); o = o || {}; - return new K.Tween(_el, _vS, _vE, o); - }; - - // multiple elements tweening - K.allTo = function (el, to, o) { - var _els = typeof el === 'object' && el.length ? el : document.querySelectorAll(el); - return new K.TweensAT(_els, to, o); - }; - K.allFromTo = function (el, f, to, o) { - var _els = typeof el === 'object' && el.length ? el : document.querySelectorAll(el); - return new K.TweensFT(_els, f, to, o); - }; - - // render functions - K._r = {}; var _r = K._r; - K._u = function(w,t) { - t = t || window.performance.now(); - if (t < w._sT && w.playing && !w.paused) { return true; } - - var p, s = s || w._sT, - d = d || w._dr, - e = ( t - s ) / d, - ve = ve || w._vE, - es = es || w._e; - e = e > 1 ? 1 : e; - - //render the CSS update - for (p in ve){ - _r[p](w,p,es(e)); - } - - if (w._uC) { w._uC.call(); } - - if (e === 1) { - if (w._r > 0) { - if ( w._r < 9999 ) { w._r--; } - - if (w._y) { w.reversed = !w.reversed; w.reverse(); } // handle yoyo - - w._sT = (w._y && !w.reversed) ? t + w._rD : t; //set the right time for delay - return true; - } else { - - if (w._cC) { w._cC.call(); } - - //stop preventing scroll when scroll tween finished - w.scrollOut(); - - // start animating chained tweens - var i = 0, ctl = w._cT.length; - for (i; i < ctl; i++) { - w._cT[i].start(w._sT + w._dr); - } - - //stop ticking when finished - w.close(); - return false; - } - } - return true; - }; - - var _u = K._u; - // internal ticker - K._t = function (t) { - var i = 0, tl; - _t = _raf(K._t); - while ( i < (tl = _tws.length) ) { - if ( _u(_tws[i],t) ) { - i++; - } else { - _tws.splice(i, 1); - } - } - return true; - }; - - // aplies the transform origin and perspective - K.perspective = function (l,w) { - if ( w._to !== undefined ) { l.style[_pfto] = w._to; } // element transform origin - if ( w._ppo !== undefined ) { l.style[_pfo] = w._ppo; } // element perspective origin - if ( w._ppp !== undefined ) { l.parentNode.style[_pfp] = w._ppp + 'px'; } // parent perspective - if ( w._pppo !== undefined ) { l.parentNode.style[_pfo] = w._pppo; } // parent perspective origin - }; - - //more internals - K.getAll = function () { return _tws; }; - K.removeAll = function () { _tws = []; }; - K.add = function (tw) { _tws.push(tw); }; - K.remove = function (tw) { - var i = _tws.indexOf(tw); - if (i !== -1) { - _tws.splice(i, 1); - } - }; - K.s = function () { _caf(_t); _t = null; }; - - // builds render functions for the render object K.render(w, p, w._e(e)); - K._queue = function (w) { - for ( var p in w._vE ) { - // checking array on every frame takes time so let's cache these - var cls = _cls.indexOf(p) !== -1, - bm = _tp.indexOf(p) !== -1 || _bm.indexOf(p) !== -1, - rd = _rd.indexOf(p) !== -1, - sc = _sc.indexOf(p) !== -1, - bg = _bg.indexOf(p) !== -1, - clp = _clp.indexOf(p) !== -1, - op = _op.indexOf(p) !== -1, - tf = p === 'transform'; - - //process styles by property / property type - if ( bm && (!(p in K._r)) ) { - K._r[p] = function(w,p,v) { - w._el.style[p] = (w._vS[p].value + (w._vE[p].value - w._vS[p].value) * v ) + w._vE[p].unit; - }; - } else if ( rd && (!(p in K._r)) ) { - if (p === 'borderRadius') { - K._r[p] = function(w,p,v) { - w._el.style[_br] = (w._vS[p].value + (w._vE[p].value - w._vS[p].value) * v ) + w._vE[p].unit; - }; - } else if (p === 'borderTopLeftRadius') { - K._r[p] = function(w,p,v) { - w._el.style[_brtl] = (w._vS[p].value + (w._vE[p].value - w._vS[p].value) * v ) + w._vE[p].unit; - }; - } else if (p === 'borderTopRightRadius') { - K._r[p] = function(w,p,v) { - w._el.style[_brtr] = (w._vS[p].value + (w._vE[p].value - w._vS[p].value) * v ) + w._vE[p].unit; - }; - } else if (p === 'borderBottomLeftRadius') { - K._r[p] = function(w,p,v) { - w._el.style[_brbl] = (w._vS[p].value + (w._vE[p].value - w._vS[p].value) * v ) + w._vE[p].unit; - }; - } else if (p === 'borderBottomRightRadius') { - K._r[p] = function(w,p,v) { - w._el.style[_brbr] = (w._vS[p].value + (w._vE[p].value - w._vS[p].value) * v ) + w._vE[p].unit; - }; - } - } else if (tf && (!(p in K._r)) ) { - - K._r[p] = function(w,p,v) { - var _tS = '', tP, rps, pps = 'perspective('+w._pp+'px) '; - for (tP in w._vE[p]) { - var t1 = w._vS[p][tP], t2 = w._vE[p][tP]; - rps = rps || _3d.indexOf(tP) !== -1 && !_isIE; - - if ( tP === 'translate' ) { - var tls = '', ts = {}, ax; - - for (ax in t2){ - var x1 = t1[ax].value || 0, x2 = t2[ax].value || 0, xu = t2[ax].unit || 'px'; - ts[ax] = x1===x2 ? x2+xu : (x1 + ( x2 - x1 ) * v) + xu; - } - tls = t2.x ? 'translate(' + ts.x + ',' + ts.y + ')' : - 'translate3d(' + ts.translateX + ',' + ts.translateY + ',' + ts.translateZ + ')'; - - _tS = (_tS === '') ? tls : (tls + ' ' + _tS); - } else if ( tP === 'rotate' ) { - var rt = '', rS = {}, rx; - - for ( rx in t2 ){ - if ( t1[rx] ) { - var a1 = t1[rx].value, a2 = t2[rx].value, au = t2[rx].unit||'deg', - av = a1 + (a2 - a1) * v; - rS[rx] = rx ==='z' ? 'rotate('+av+au+')' : rx + '(' + av + au + ') '; - } - } - rt = t2.z ? rS.z : (rS.rotateX||'') + (rS.rotateY||'') + (rS.rotateZ||''); - - _tS = (_tS === '') ? rt : (_tS + ' ' + rt); - } else if (tP==='skew') { - var sk = '', sS = {}; - for ( var sx in t2 ){ - if ( t1[sx] ) { - var s1 = t1[sx].value, s2 = t2[sx].value, su = t2[sx].unit||'deg', - sv = s1 + (s2 - s1) * v; - sS[sx] = sx + '(' + sv + su + ') '; - } - } - sk = (sS.skewX||'') + (sS.skewY||''); - _tS = (_tS === '') ? sk : (_tS + ' ' + sk); - } else if (tP === 'scale') { - var sc1 = t1.value, sc2 = t2.value, - s = sc1 + (sc2 - sc1) * v, scS = tP + '(' + s + ')'; - _tS = (_tS === '') ? scS : (_tS + ' ' + scS); - } - } - w._el.style[_tr] = rps || ( w._pp !== undefined && w._pp !== 0 ) ? pps + _tS : _tS; - }; - - } else if ( cls && (!(p in K._r)) ) { - K._r[p] = function(w,p,v) { - var _c = {}; - for (var c in w._vE[p].value) { - if ( c !== 'a' ){ - _c[c] = parseInt(w._vS[p].value[c] + (w._vE[p].value[c] - w._vS[p].value[c]) * v )||0; - } else { - _c[c] = (w._vS[p].value[c] && w._vE[p].value[c]) ? parseFloat(w._vS[p].value[c] + (w._vE[p].value[c] - w._vS[p].value[c]) * v) : null; - } - } - - if ( w._hex ) { - w._el.style[p] = K.rth( parseInt(_c.r), parseInt(_c.g), parseInt(_c.b) ); - } else { - w._el.style[p] = !_c.a || _isIE8 ? 'rgb(' + _c.r + ',' + _c.g + ',' + _c.b + ')' : 'rgba(' + _c.r + ',' + _c.g + ',' + _c.b + ',' + _c.a + ')'; - } - }; - } else if ( sc && (!(p in K._r)) ) { - K._r[p] = function(w,p,v) { - w._el = (w._el === undefined || w._el === null) ? _sct : w._el; - w._el.scrollTop = w._vS[p].value + (w._vE[p].value - w._vS[p].value) * v; - }; - } else if ( bg && (!(p in K._r)) ) { - K._r[p] = function(w,p,v) { - var px1 = w._vS[p].x.v, px2 = w._vE[p].x.v, py1 = w._vS[p].y.v, py2 = w._vE[p].y.v, - px = (px1 + ( px2 - px1 ) * v), pxu = '%', py = (py1 + ( py2 - py1 ) * v), pyu = '%'; - w._el.style[p] = px + pxu + ' ' + py + pyu; - }; - } else if ( clp && (!(p in K._r)) ) { - K._r[p] = function(w,p,v) { - var h = 0, cl = []; - for (h;h<4;h++){ - var c1 = w._vS[p][h].v, c2 = w._vE[p][h].v, cu = w._vE[p][h].u || 'px'; - cl[h] = ((c1 + ( c2 - c1 ) * v)) + cu; - } - w._el.style[p] = 'rect('+cl+')'; - }; - } else if ( op && (!(p in K._r)) ) { - if (_isIE8) { - K._r[p] = function(w,p,v) { - w._el.style.filter = "alpha(opacity=" + ( w._vS[p].value + (w._vE[p].value - w._vS[p].value) * v) * 100 + ")"; - }; - } else { - K._r[p] = function(w,p,v) { - w._el.style.opacity = w._vS[p].value + (w._vE[p].value - w._vS[p].value) * v; - }; - } - } - } - }; - - // process properties - K.prP = function (t, e) { // process tween properties for .fromTo() method - var _st = {}, - tr = e === true ? _tfE : _tfS, - tl = e === true ? _tlE : _tlS, - rt = e === true ? _rtE : _rtS; - - tl = {}; tr = {}; - - for (var x in t) { - if (_tf.indexOf(x) !== -1) { - - if (x !== 'translate' && /translate/.test(x)) { //process translate3d - var ta = ['X', 'Y', 'Z'], f = 0; //coordinates // translate[x] = pp(x, t[x]); - - for (f; f < 3; f++) { - var a = ta[f]; - if ( /3d/.test(x) ) { - tl['translate' + a] = K.pp('translate' + a, t[x][f]); - } else { - tl['translate' + a] = ('translate' + a in t) ? K.pp('translate' + a, t['translate' + a]) : { value: 0, unit: 'px' }; - } - } - - tr['translate'] = tl; - } else if ( x !== 'rotate' && /rotate|skew/.test(x)) { //process rotation - var ap = /rotate/.test(x) ? 'rotate' : 'skew', ra = ['X', 'Y', 'Z'], r = 0, - _rt = {}, _sk = {}, rt = ap === 'rotate' ? _rt : _sk; - for (r; r < 3; r++) { - var v = ra[r]; - if ( t[ap+v] !== undefined && x !== 'skewZ' ) { - rt[ap+v] = K.pp(ap + v, t[ap+v]); - } - } - - tr[ap] = rt; - } else if ( x === 'translate' || x === 'rotate' || x === 'scale' ) { //process 2d translation / rotation - tr[x] = K.pp(x, t[x]); - } - - _st['transform'] = tr; - - } else if (_tf.indexOf(x) === -1) { - _st[x] = K.pp(x, t[x]); - } - } - return _st; - }; - - // _cls _sc _op _bm _tp _bg _tf - K.pp = function(p, v) {//process single property - if (_tf.indexOf(p) !== -1) { - var t = p.replace(/X|Y|Z/, ''), tv; - if (p === 'translate3d') { - tv = v.split(','); - return { - translateX : { value: K.truD(tv[0]).v, unit: K.truD(tv[0]).u }, - translateY : { value: K.truD(tv[1]).v, unit: K.truD(tv[1]).u }, - translateZ : { value: K.truD(tv[2]).v, unit: K.truD(tv[2]).u } - }; - } else if (p !== 'translate' && t === 'translate') { - return { value: K.truD(v).v, unit: (K.truD(v).u||'px') }; - } else if (p !== 'rotate' && (t === 'skew' || t === 'rotate') && p !== 'skewZ' ) { - return { value: K.truD(v).v, unit: (K.truD(v,p).u||'deg') }; - } else if (p === 'translate') { - tv = typeof v === 'string' ? v.split(',') : v; var t2d = {}; - if (tv instanceof Array) { - t2d.x = { value: K.truD(tv[0]).v, unit: K.truD(tv[0]).u }, - t2d.y = { value: K.truD(tv[1]).v, unit: K.truD(tv[1]).u } - } else { - t2d.x = { value: K.truD(tv).v, unit: K.truD(tv).u }, - t2d.y = { value: 0, unit: 'px' } - } - return t2d; - } else if (p === 'rotate') { - var r2d = {}; - r2d.z = { value: parseInt(v, 10), unit: (K.truD(v,p).u||'deg') }; - return r2d; - } else if (p === 'scale') { - return { value: parseFloat(v, 10) }; - } - } - if (_tp.indexOf(p) !== -1 || _bm.indexOf(p) !== -1) { - return { value: K.truD(v).v, unit: K.truD(v).u }; - } - if (_op.indexOf(p) !== -1) { - return { value: parseFloat(v, 10) }; - } - if (_sc.indexOf(p) !== -1) { - return { value: parseFloat(v, 10) }; - } - if (_clp.indexOf(p) !== -1) { - if ( v instanceof Array ){ - return [ K.truD(v[0]), K.truD(v[1]), K.truD(v[2]), K.truD(v[3]) ]; - } else { - var ci; - if ( /rect/.test(v) ) { - ci = v.replace(/rect|\(|\)/g,'').split(/\s|\,/); - } else if ( /auto|none|initial/.test(v) ){ - ci = _d[p]; - } - return [ K.truD(ci[0]), K.truD(ci[1]), K.truD(ci[2]), K.truD(ci[3]) ]; - } - } - if (_cls.indexOf(p) !== -1) { - return { value: K.truC(v) }; - } - if (_bg.indexOf(p) !== -1) { - if ( v instanceof Array ){ - return { x: K.truD(v[0])||{ v: 50, u: '%' }, y: K.truD(v[1])||{ v: 50, u: '%' } }; - } else { - var posxy = v.replace(/top|left/g,0).replace(/right|bottom/g,100).replace(/center|middle/,50).split(/\s|\,/g), - xp = K.truD(posxy[0]), yp = K.truD(posxy[1]); - return { x: xp, y: yp }; - } - } - if (_rd.indexOf(p) !== -1) { - var rad = K.truD(v); - return { value: rad.v, unit: rad.u }; - } - }; - - K.truD = function (d,p) { //true dimension returns { v = value, u = unit } - var x = parseInt(d) || 0, mu = ['px','%','deg','rad','em','rem','vh','vw'], l = mu.length, - y = getU(); - function getU() { - var u,i=0; - for (i;i 0) { self._r = self.repeat; } - if (self._y && self.reversed===true) { self.reverse(); self.reversed = false; } - self.playing = false; - },61) - }; - - // the multi elements Tween constructs - K.TweensAT = function (els, vE, o) { // .to - this.tweens = []; var i, tl = els.length, _o = []; - for ( i = 0; i < tl; i++ ) { - _o[i] = o || {}; o.delay = o.delay || 0; - _o[i].delay = i>0 ? o.delay + (o.offset||0) : o.delay; - this.tweens.push( K.to(els[i], vE, _o[i]) ); - } - }; - K.TweensFT = function (els, vS, vE, o) { // .fromTo - this.tweens = []; var i, tl = els.length, _o = []; - for ( i = 0; i < tl; i++ ) { - _o[i] = o || {}; o.delay = o.delay || 0; - _o[i].delay = i>0 ? o.delay + (o.offset||0) : o.delay; - this.tweens.push( K.fromTo(els[i], vS, vE, _o[i]) ); - } - }; - var ws = K.TweensAT.prototype = K.TweensFT.prototype; - ws.start = function(t){ - t = t || window.performance.now(); - var i, tl = this.tweens.length; - for ( i = 0; i < tl; i++ ) { - this.tweens[i].start(t); - } - return this; - } - ws.stop = function(){ for ( var i = 0; i < this.tweens.length; i++ ) { this.tweens[i].stop(); } return this; } - ws.pause = function(){ for ( var i = 0; i < this.tweens.length; i++ ) { this.tweens[i].pause(); } return this; } - ws.play = ws.resume = function(){ for ( var i = 0; i < this.tweens.length; i++ ) { this.tweens[i].play(); } return this; } - - - //returns browser prefix - function getPrefix() { - var div = document.createElement('div'), i = 0, pf = ['Moz', 'moz', 'Webkit', 'webkit', 'O', 'o', 'Ms', 'ms'], pl = pf.length, - s = ['MozTransform', 'mozTransform', 'WebkitTransform', 'webkitTransform', 'OTransform', 'oTransform', 'MsTransform', 'msTransform']; - - for (i; i < pl; i++) { if (s[i] in div.style) { return pf[i]; } } - div = null; - } - - return K; -})); \ No newline at end of file diff --git a/package.json b/package.json deleted file mode 100644 index cc74455..0000000 --- a/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "kute.js", - "version": "1.0.1", - "description": "A minimal Native Javascript animation engine with jQuery plugin.", - "main": "kute.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/thednp/kute.js.git" - }, - "keywords": [ - "kute.js", - "animation engine", - "animations", - "native-javascript" - ], - "author": "thednp", - "license": "MIT", - "bugs": { - "url": "https://github.com/thednp/kute.js/issues" - }, - "homepage": "http://thednp.github.io/kute.js", - "dependencies": {} -}