//自动撑高后的全局回调方法设置 var jsmart = {}; jsmart.autoComputeCallback = function () { } if (!jQuery) { throw new Error("nsmart requires jQuery") } +function (window, $, document, undefined) { "use strict"; var smartH$ = window.smartH$ = new function () { var b = this, pb = /\S+/g, B = 1, Z = 2, cb = 3, bb = 4, fb = 5, C, j = 0, c = 0, k = 0, r = 0, s = 0, v = navigator, kb = v.appName, f = v.userAgent, q = document.documentElement, h = parseFloat; function xb() { if (!C) { C = { $Touchable: "ontouchstart" in window || "createTouch" in document }; var a; if (v.pointerEnabled || (a = v.msPointerEnabled)) C.$TouchActionAttr = a ? "msTouchAction" : "touchAction" } return C } function m(l) { if (!j) { j = -1; if (kb == "Microsoft Internet Explorer" && !!window.attachEvent && !!window.ActiveXObject) { var g = f.indexOf("MSIE"); j = B; k = h(f.substring(g + 5, f.indexOf(";", g))); /*@cc_on r=@_jscript_version@*/ ; c = document.documentMode || k } else if (kb == "Netscape" && !!window.addEventListener) { var e = f.indexOf("Firefox"), b = f.indexOf("Safari"), i = f.indexOf("Chrome"), d = f.indexOf("AppleWebKit"); if (e >= 0) { j = Z; c = h(f.substring(e + 8)) } else if (b >= 0) { var m = f.substring(0, b).lastIndexOf("/"); j = i >= 0 ? bb : cb; c = h(f.substring(m + 1, b)) } else { var a = /Trident\/.*rv:([0-9]{1,}[\.0-9]{0,})/i.exec(f); if (a) { j = B; c = k = h(a[1]) } } if (d >= 0) s = h(f.substring(d + 12)) } else { var a = /(opera)(?:.*version|)[ \/]([\w.]+)/i.exec(f); if (a) { j = fb; c = h(a[2]) } } } return l == j } function i() { return m(B) } function Y() { return i() && (c < 6 || document.compatMode == "BackCompat") } function qb() { return m(Z) } function ab() { return m(cb) } function tb() { return m(bb) } function eb() { return m(fb) } function U() { return ab() && s > 534 && s < 535 } function y() { m(); return s > 537 || c > 42 || j == B && c >= 11 } function W() { return i() && c < 10 } function V(a) { var b, c; return function (f) { if (!b) { b = true; var d = a.substr(0, 1).toUpperCase() + a.substr(1); e([a].concat(["WebKit", "ms", "Moz", "O", "webkit"]), function (g, e) { var b = a; if (e) b = g + d; if (f.style[b] != undefined) return c = b }) } return c } } function T(b) { var a; return function (c) { a = a || V(b)(c) || b; return a } } var D = T("transform"); function jb(a) { return {}.toString.call(a) } var gb = {}; e(["Boolean", "Number", "String", "Function", "Array", "Date", "RegExp", "Object"], function (a) { gb["[object " + a + "]"] = a.toLowerCase() }); function e(b, d) { var a, c; if (jb(b) == "[object Array]") { for (a = 0; a < b.length; a++) if (c = d(b[a], a, b)) return c } else for (a in b) if (c = d(b[a], a, b)) return c } function x(a) { return a == null ? String(a) : gb[jb(a)] || "object" } function hb(a) { for (var b in a) return true } function t(a) { try { return x(a) == "object" && !a.nodeType && a != a.window && (!a.constructor || {}.hasOwnProperty.call(a.constructor.prototype, "isPrototypeOf")) } catch (b) { } } function g(a, b) { return { x: a, y: b } } function nb(b, a) { setTimeout(b, a || 0) } function u(b, d, c) { var a = !b || b == "inherit" ? "" : b; e(d, function (c) { var b = c.exec(a); if (b) { var d = a.substr(0, b.index), e = a.substr(b.index + b[0].length + 1, a.length - 1); a = d + e } }); a = c + (!a.indexOf(" ") ? "" : " ") + a; return a } function I(b, a) { if (c < 9) b.style.filter = a } b.$Device = xb; b.$IsBrowserIE = i; b.$IsBrowserIeQuirks = Y; b.$IsBrowserFireFox = qb; b.$IsBrowserSafari = ab; b.$IsBrowserChrome = tb; b.$IsBrowserOpera = eb; b.$IsBrowserBadTransform = U; b.$IsBrowser3dSafe = y; b.$IsBrowserIe10Earlier = W; b.$BrowserVersion = function () { return c }; b.$BrowserEngineVersion = function () { return k || c }; b.$WebKitVersion = function () { m(); return s }; }; var smartAm = function (element, options) { this.$element = $(element); this.options = $.extend({}, smartAm.DEFAULTS, options); this.initTop = this.$element.position().top; this.initLeft = this.$element.position().left; this.prefixes = ["", "-moz-", "-o-animation-", "-webkit-"]; this.queue = []; this.ac = options; this.queue[0] = (this.ac.animationName + this.ac.direction) || ''; this.st = null; } smartAm.version = "1.0"; smartAm.DEFAULTS = { container: window, threshold: 0 }; smartAm.prototype = { belowthefold: function ($element, settings) { var fold; if (settings.container === undefined || settings.container === window) { var $window = $(window); fold = (window.innerHeight ? window.innerHeight : $window.height()) + $window.scrollTop(); } else { fold = $(settings.container).offset().top + $(settings.container).height(); } return fold <= $element.offset().top - settings.threshold; }, rightoffold: function ($element, settings) { return false; var fold; if (settings.container === undefined || settings.container === window) { var $window = $(window); fold = $window.width() + $window.scrollLeft(); } else { fold = $(settings.container).offset().left + $(settings.container).width(); } return fold <= $element.offset().left - settings.threshold; }, abovethetop: function ($element, settings) { var fold; if (settings.container === undefined || settings.container === window) { fold = $(window).scrollTop(); } else { fold = $(settings.container).offset().top; } return fold >= $element.offset().top + settings.threshold + $element.height(); }, leftofbegin: function ($element, settings) { var fold; if (settings.container === undefined || settings.container === window) { fold = $(window).scrollLeft(); } else { fold = $(settings.container).offset().left; } return fold >= $element.offset().left + settings.threshold + $element.width(); }, initQ: function () { if (this.queue.length === 0) { this.queue[0] = (this.ac.animationName + this.ac.direction) || ''; } }, play: function () { this.addDoneAtt(); this.initQ(); var device = smartH$.$Device(); if (!device.$Touchable && smartH$.$IsBrowserIE() && smartH$.$IsBrowserIe10Earlier() < 10) { this.playIE(); } else { this.playNoraml(); } }, replay: function () { this.removeDoneAtt(); this.play(); }, prev: function (data) { this.cleanse(); this.$element.css({ 'opacity': 0 }); if (typeof data === 'undefined') { this.ac = $.parseJSON(this.$element.attr('smanim')); this.queue[0] = (this.ac.animationName + this.ac.direction) || ''; this.$element.attr('prevHisAni', this.queue[0]); this.play(); } else { this.addDoneAtt(); this.palyWithData(data); } }, stop: function () { if (this.st !== null) { clearTimeout(this.st); } var ani = (this.ac.animationName + this.ac.direction) || '' this.$element.removeClass(ani).css({ 'opacity': 0 }).stop(true, true); }, playIE: function () { if (this.isAmInFix(this.queue[0])) { this[this.queue[0]](); } else { this.playNoraml(); } }, playNoraml: function () { if (this.queue.length == 0) { return; } var ai = this.prefixes.length; while (ai--) { this.$element.css(this.prefixes[ai] + "animation-duration", this.options.duration + "s"); this.$element.css(this.prefixes[ai] + "animation-delay", this.options.delay + "s"); this.$element.css(this.prefixes[ai] + "animation-iteration-count", this.options.infinite); } this.$element.addClass(this.queue[0]); // Add the options for each prefix var $me = this; this.end("AnimationEnd", function () { $me.$element.css({ 'opacity': 1 }); // If there are more, clean it up and move on if ($me.$element.hasClass($me.queue[0])) { if (!$me.options.keep && !($me.queue.length == 0 || $me.options.infinite === 'infinite')) { $me.cleanse(); } $me.queue.shift(); if ($me.queue.length) { $me.animate(); } else { //fixed smview has animate in container $me.execChildAnim($me.$element); } } }); }, palyWithData: function (data) { var ai = this.prefixes.length; var animationName = data.animationName + data.direction; this.$element.attr('prevHisAni', animationName); while (ai--) { this.$element.css(this.prefixes[ai] + "animation-duration", data.duration + "s"); this.$element.css(this.prefixes[ai] + "animation-delay", data.delay + "s"); this.$element.css(this.prefixes[ai] + "animation-iteration-count", data.infinite); } this.$element.addClass(data.animationName + data.direction); // Add the options for each prefix var $me = this; this.end("AnimationEnd", function () { $me.$element.css({ 'opacity': 1 }); $me.cleanAnim(animationName); //fixed smview has animate in container $me.execChildAnim($me.$element); }); }, addDoneAtt: function () { this.$element.attr('sm-finished', true) }, removeDoneAtt: function () { this.$element.removeAttr('sm-finished'); }, fadeIn: function () { var me = this; this.st = setTimeout(function () { me.$element.animate({ opacity: 1 }, (me.ac.duration || 0) * 1000, function () { me.execChildAnim(me.$element); }); }, (me.ac.delay || 0) * 1000); }, fadeInLeft: function () { var me = this; this.st = setTimeout(function () { var p = parseInt(me.$element.css("left")); me.$element.animate({ left: p - me.$element.width() }).animate({ left: p, opacity: 1 }, (me.ac.duration || 0) * 1000, function () { me.execChildAnim(me.$element); }); }, (me.ac.delay || 0) * 1000); }, fadeInLeftBig: function () { var me = this; this.st = setTimeout(function () { var p = parseInt(me.$element.css("left")); me.$element.animate({ left: 0 - me.$element.width() }).animate({ left: p, opacity: 1 }, (me.ac.duration || 0) * 1000, function () { me.execChildAnim(me.$element); }); }, (me.ac.delay || 0) * 1000); }, fadeInRight: function () { var me = this; this.st = setTimeout(function () { var p = parseInt(me.$element.css("left")); var np = p + me.$element.width(); var w = $(window).width(); if (np > w) { np = w - me.$element.width(); } me.$element.animate({ left: np }).animate({ left: p, opacity: 1 }, (me.ac.duration || 0) * 1000, function () { me.execChildAnim(me.$element); }); }, (me.ac.delay || 0) * 1000); }, fadeInRightBig: function () { var me = this; this.st = setTimeout(function () { var p = parseInt(me.$element.css("left")); var np = p + me.$element.width(); var w = $(window).width(); if (np > w) { np = w - me.$element.width(); } me.$element.animate({ right: 0 - me.$element.width() }).animate({ left: p, opacity: 1 }, (me.ac.duration || 0) * 1000, function () { me.execChildAnim(me.$element); }); }, (me.ac.delay || 0) * 1000); }, fadeInDown: function () { var me = this; this.st = setTimeout(function () { var p = parseInt(me.$element.css("top")); me.$element.animate({ top: p - me.$element.height() }).animate({ top: p, opacity: 1 }, (me.ac.duration || 0) * 1000, function () { me.execChildAnim(me.$element); }); }, (me.ac.delay || 0) * 1000); }, fadeInDownBig: function () { var me = this; this.st = setTimeout(function () { var p = parseInt(me.$element.css("top")); me.$element.animate({ top: 0 - me.$element.height() }).animate({ top: p, opacity: 1 }, (me.ac.duration || 0) * 1000, function () { me.execChildAnim(me.$element); }); }, (me.ac.delay || 0) * 1000); }, fadeInUp: function () { var me = this; this.st = setTimeout(function () { var p = parseInt(me.$element.css("top")); me.$element.animate({ top: p + me.$element.height() }).animate({ top: p, opacity: 1 }, (me.ac.duration || 0) * 1000, function () { me.execChildAnim(me.$element); }); }, (me.ac.delay || 0) * 1000); }, fadeInUpBig: function () { var me = this; this.st = setTimeout(function () { var p = parseInt(me.$element.css("top")); me.$element.animate({ bottom: 0 - me.$element.height() }).animate({ top: p, opacity: 1 }, (me.ac.duration || 0) * 1000, function () { me.execChildAnim(me.$element); }); }, (me.ac.delay || 0) * 1000); }, slideInLeft: function () { var me = this; this.st = setTimeout(function () { var p = parseInt(me.$element.css("left")); me.$element.animate({ left: p - me.$element.width() }).animate({ opacity: 1 }).animate({ left: p }, (me.ac.duration || 0) * 1000 + 300, function () { me.execChildAnim(me.$element); }); }, (me.ac.delay || 0) * 1000); }, slideInRight: function () { var me = this; this.st = setTimeout(function () { var p = parseInt(me.$element.css("left")); var np = p + me.$element.width(); var w = $(window).width(); if (np > w) { np = w - me.$element.width(); } me.$element.animate({ left: np }).animate({ opacity: 1 }).animate({ left: p }, (me.ac.duration || 0) * 1000, function () { me.execChildAnim(me.$element); }); }, (me.ac.delay || 0) * 1000); }, slideInDown: function () { var me = this; this.st = setTimeout(function () { var p = parseInt(me.$element.css("top")); me.$element.animate({ top: p - me.$element.height() }).animate({ opacity: 1 }).animate({ top: p }, (me.ac.duration || 0) * 1000, function () { me.execChildAnim(me.$element); }); }, (me.ac.delay || 0) * 1000); }, slideInUp: function () { var me = this; this.st = setTimeout(function () { var p = parseInt(me.$element.css("top")); me.$element.animate({ top: p + me.$element.height() }).animate({ opacity: 1 }).animate({ top: p }, (me.ac.duration || 0) * 1000, function () { me.execChildAnim(me.$element); }); }, (me.ac.delay || 0) * 1000); }, isAmInFix: function (am) { var res = false; switch (am) { case 'fadeIn': case 'fadeInLeft': case 'fadeInLeftBig': case 'fadeInRight': case 'fadeInRightBig': case 'fadeInRightBig': case 'fadeInDown': case 'fadeInDownBig': case 'fadeInUp': case 'fadeInUpBig': case 'slideInLeft': case 'slideInRight': case 'slideInDown': case 'slideInUp': res = true; break; default: break; } return res; }, animate: function () { var isfinished = this.$element.attr('sm-finished'); if (this.abovethetop(this.$element, this.options) || this.leftofbegin(this.$element, this.options)) { /* Nothing. */ } else if (typeof isfinished === 'undefined' && !this.belowthefold(this.$element, this.options) && !this.rightoffold(this.$element, this.options) && typeof this.$element.attr('sm-finished') === 'undefined') { this.play(); } }, cleanse: function () { var hisAni = this.$element.attr('prevHisAni'); if (typeof hisAni !== 'undefined' && hisAni !== '') { this.$element.removeClass('hisAni'); } this.cleanAnim(this.queue[0]); }, cleanAnim: function (name) { this.$element.removeClass(name); var ai = this.prefixes.length; while (ai--) { this.$element.css(this.prefixes[ai] + "animation-duration", ""); this.$element.css(this.prefixes[ai] + "animation-delay", ""); this.$element.css(this.prefixes[ai] + "animation-iteration-count", ""); } }, end: function (type, cb) { var $me = this; var binding = type.toLowerCase() + " webkit" + type + " o" + type + " MS" + type; this.$element.bind(binding, function () { if (typeof cb === 'function') { cb(); } $me.$element.unbind(binding); }); }, execChildAnim: function (e) { e.attr('smexecuted', '1'); if (e.attr('iscontainer') === 'True') { e.find('.animated').smanimate(); } } } function Plugin(option, args) { var options = option; var elements = this; $(window).on('scroll', function () { elements.each(function () { var $this = $(this); var data = $this.data('smart.animation'); if (data) { data.animate(); } }); }); if (smartH$.$Device().$Touchable) { $(document) .on('ps-scroll-y', function () { elements.each(function () { var $this = $(this); var data = $this.data('smart.animation'); if (data) { data.animate(); } }); }); } return this.each(function () { var smOption = options; var action = typeof smOption == 'string' && smOption; var self = this; var $this = $(self); var pvid = $this.attr('pvid'); if (typeof pvid !== 'undefined' && pvid !== '') { var $parent = $('#' + pvid); if ($parent.hasClass('animated') && $parent.attr('smexecuted') !== '1') { return true; } } if (smOption == null) { var animateAttr = $this.attr('smanim'); if (typeof (animateAttr) != 'undefined') { smOption = $.parseJSON(animateAttr); } } var data = $this.data('smart.animation'); if (!data) { if (typeof (smOption) === 'object') { $this.data('smart.animation', (data = new smartAm(this, smOption))); data.animate(); } else { smOption = {}; $this.data('smart.animation', (data = new smartAm(this, smOption))); data.animate(); } } else { if (action) { data.options = $.extend({}, smartAm.DEFAULTS, $.parseJSON($this.attr('smanim'))); data.ac = data.options; if (typeof args === 'undefined') { data[smOption](); } else { data[smOption](args); } } else { data.options = $.extend({}, smartAm.DEFAULTS, data.options); data.ac = data.options; data.queue[0] = (data.ac.animationName + data.ac.direction) || ''; data.animate(); } } }); } $.fn.smanimate = Plugin; $.fn.smanimate.Constructor = smartAm; }(typeof window === 'undefined' ? this : window, jQuery, document);