'use strict'; var _typeof2 = typeof symbol === "function" && typeof symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof symbol === "function" && obj.constructor === symbol && obj !== symbol.prototype ? "symbol" : typeof obj; }; var _typeof = typeof symbol === "function" && _typeof2(symbol.iterator) === "symbol" ? function (obj) { return typeof obj === "undefined" ? "undefined" : _typeof2(obj); } : function (obj) { return obj && typeof symbol === "function" && obj.constructor === symbol && obj !== symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof2(obj); }; (function ($, window, undefined) { window.you = { init: function init() { var json = arguments[0] ? arguments[0] : {}; if (json.imgauto) { $('img').each(function () { var t = $(this); if (t.attr('img-auto')) { t.attr('img-auto') == 'cover' ? t.imgauto('cover') : t.imgauto(); } }); } $('body').fadeto('fast', 1); return this; }, rem: function rem(size) { size = size || 640; $(window).width() > 1024 ? $('html').css('font-size', 320) : $('html').css('font-size', $(window).width() / size * 100); return this; }, nav: function nav() { var nav = $('#nav'); var btn = $('#nav>ul>li>a'); $('#menu').click(function () { nav.addclass('in'); }); nav.click(function () { nav.removeclass('in'); }); $('#nav>ul').click(function (event) { event.stoppropagation(); }); btn.each(function () { var t = $(this); if (t.next('ul').children().length) { t.prop('href', 'javascript:;').append(''); } }).click(function (event) { var t = $(this); var abtn = btn.filter(function (argument) { return $(this).hasclass('in'); }); var slide = function slide(obj, ud) { if (ud == 'down') { obj.addclass('in').next('ul').slidedown('fast'); } else { obj.removeclass('in').next('ul').slideup('fast'); } }; if (abtn === t) { slide(t, 'up'); } else { slide(t, 'down'); slide(abtn, 'up'); } }); return this; }, /*使用方法 var throttled = you.letter(function () {}) $(window).scroll(throttled); */ letter: function letter(fn) { if (typeof arguments[0] != 'function') return; fn(); var times = typeof arguments[1] != 'number' ? 300 : arguments[1]; var timer = null; var st = new date().gettime(); return function () { var et = new date().gettime(); if (et - st < times) { cleartimeout(timer); timer = settimeout(function () { //return fn.apply(this,arguments); fn(); }, times); } else { cleartimeout(timer); st = et; fn(); } }; }, css3: function () { var div = document.createelement('div'), vendors = 'ms o moz webkit'.split(' '); return function (prop) { var len = vendors.length; if (typeof prop != 'string') return false; if (prop in div.style) return true; prop = prop.replace(/^[a-z]/, function (val) { return val.touppercase(); }); while (len--) { if (vendors[len] + prop in div.style) { return true; } } return false; }; }(), css3_3d: function css3_3d() { var docelement = document.documentelement; var support = you.css3('perspective'); var body = document.body; if (support && 'webkitperspective' in docelement.style) { var style = document.createelement('style'); style.type = 'text/css'; style.innerhtml = '@media (transform-3d),(-webkit-transform-3d){#css3_3d_test{left:9px;position:absolute;height:3px;}}'; body.appendchild(style); var div = document.createelement('div'); div.id = 'css3_3d_test'; body.appendchild(div); support = div.offsetleft === 9 && div.offsetheight === 3; } you.css3_3d = function () { return support; }; return support; }, //延迟加载 lazyload: function lazyload(obj, move) { obj.each(function (i) { var t = $(this); if (typeof t.attr('data-src') == 'undefined' && typeof move == 'undefined') { you.lazyload(obj.not(t)); return false; } t.show = function () { var top = $(window).height() + $(window).scrolltop(); if (top > t.offset().top - (parseint(t.css('top')) || 0)) { //回调函数型 if (typeof move == 'function') { move.call(t); //文字运动显示型 } else if (move) { t.animate({ top: 0, left: 0 }, parseint(t.attr('timer')) || 2000, function () {}); //图片延迟加载 } else { t.attr('src', t.attr('data-src')).removeattr('data-src'); } $(window).unbind('scroll', t.show); } else { return false; } }; if (t.show() === false) { $(window).bind('scroll', t.show); } else { settimeout(function () { you.lazyload(obj.not(t)); }); return false; } }); return this; }, tab: function tab(tab, list, fn) { var tab = $(tab), list = $(list), show = function show(t) { var index = $(t).data('i'); tab.removeclass('active').eq(index).addclass('active'); list.hide().eq(index).stop(true, true).fadeto(0, .5).fadeto('fast', 1); if (fn) fn(t); }; tab.each(function (i) { tab.eq(i).data('i', i); }).click(function () { show(this); }); show(tab.first()); return this; }, scrolltop: function scrolltop() { var oa, px, hb, win, box, throttled, box_win_top, timer = null; typeof arguments[1] != 'number' ? px = 150 : px = arguments[1]; if (_typeof(arguments[0]) == 'object') { if (arguments[2] == 'box') { hb = win = arguments[0]; box = oa = $("a[href='#top']"); throttled = you.letter(function () { win.scrolltop() > px ? oa.fadein() : oa.fadeout('fast'); }); } else { hb = $('html,body'); win = $(window); box = arguments[0]; oa = box.find("a[href='#top']"); throttled = you.letter(function () { box_win_top = (win.height() - box.height()) / 2; box.animate({ 'top': box_win_top + win.scrolltop() }); if (win.scrolltop() + box_win_top > px && box.is(':hidden')) { box.stop(true, true).fadein(); } if (win.scrolltop() + box_win_top < px && !box.is(':hidden')) { box.stop(true).fadeout('fast'); } }); } } else { hb = $('html,body'); win = $(window); box = oa = $("a[href='#top']"); throttled = you.letter(function () { win.scrolltop() > px ? oa.fadein() : oa.fadeout('fast'); }); } oa.click(function () { event.stoppropagation(); event.preventdefault(); hb.animate({ scrolltop: 0 }); box.fadeout(); }); win.scroll(throttled); return this; } }; $.fn.roll = function () { var t = this, json = arguments[0] ? arguments[0] : {}; if (typeof json.num != 'number') json.num = 1; if (typeof json.timer != 'number') json.timer = 6000; if (typeof json.speed != 'number') json.speed = 400; if (typeof json.easing != 'string') json.easing = 'swing'; if (typeof json.timing != 'string') json.timing = 'ease-out'; if (typeof json.adaptive === 'undefined') json.adaptive = true; if (typeof json.center === 'undefined') json.center = true; var oul = t.find('ul'), oli = oul.find('li'), oll = oli.length, ow = oli.outerwidth(true), banner_l = json.lbtn || t.find('.btn_l'), banner_r = json.rbtn || t.find('.btn_r'), btn = t.find('.banner_btn').find('a'), oindex = -oll, timer = null, movein = false, outer = false, sx = 0, ex = 0, downtime = 0, _l = 0, css3d = you.css3_3d(), move, banner_btn, banner_btn_span, suspend, _w, cw, dcenter, bresize, translate3d = function translate3d() { return 'translate3d(' + ow * oindex + 'px, 0px, 0px)'; }, toleft = function toleft() { return ow * oindex; }; t.roll_stop = function () { clearinterval(timer); }; t.roll_start = function (bl) { if (bl) { movein = false; }; clearinterval(timer); timer = setinterval(function () { move('-'); }, json.timer); }; oul.html(oul.html() + oul.html() + oul.html()); oli = oul.find('li'); oll = oli.length; t.css({ position: 'relative', overflow: 'hidden', margin: '0 auto', width: json.width ? json.width : json.banner ? '100%' : json.num * ow }); oli.css({ width: json.banner ? ow : oli.width(), height: 'auto', float: 'left', position: 'relative', overflow: 'hidden' }); oul.css({ width: oll * ow, height: 'auto' }); if (json.height) t.height(json.height); if (json.btn) { banner_btn = $('
'); banner_btn_span = $(''); for (var i = 0; i < oll / 3; i++) { banner_btn_span.append(''); } btn = banner_btn_span.find('a'); btn.first().addclass('in'); banner_btn.append(banner_btn_span); t.append(banner_btn); if (json.btn == 'all') { t.append(''); banner_l = t.find('.banner_l'); banner_r = t.find('.banner_r'); } } suspend = btn.add(banner_l).add(banner_r); if (json.banner) { dcenter = $('div.center:first'); bresize = function bresize() { _w = t.width(); cw = dcenter.width(); if (json.adaptive) { ow = _w; } else { ow = _w > cw ? _w : cw; } oli.width(ow); oul.width(oll * ow); if (css3d) { oul.css({ 'transform': translate3d(), 'transition': 'transform 0ms' }); } else { oul.css({ left: toleft() }); } }; bresize(); $(window).resize(function () { bresize(); }); } else { suspend.add(oli); } if (css3d) { oul.css({ 'transform': translate3d() }).on('webkittransitionend', function () { if (movein) { if (oindex >= 0) { oindex = -oll / 3; oul.css({ 'transform': translate3d(), 'transition': 'transform 0ms' }); } if (oindex <= -(oll - json.num)) { oindex = -(2 * oll / 3 - json.num); oul.css({ 'transform': translate3d(), 'transition': 'transform 0ms' }); } movein = false; } }); } else { oul.css({ position: 'absolute', top: 0, left: toleft() }); } // if (json.center) oul.find('img').imgauto(true, { // imgautostart: function(img){ // if (json.banner && !json.height) { // t.height(_w / img.width * img.height); // } // } // }); move = function move(dir) { if (movein) return; movein = true; if (typeof dir != 'undefined') { dir == '+' ? oindex++ : oindex--; } btn.removeclass('in').eq(-oindex % (oll / 3)).addclass('in'); if (css3d) { oul.css({ 'transform': translate3d(), 'transition': 'transform ' + json.speed + 'ms ' + json.timing }); } else { oul.stop(true, true).animate({ left: toleft() }, json.speed, json.easing, function () { if (oindex >= 0) { oindex = -oll / 3; oul.css('left', toleft()); } if (oindex <= -(oll - json.num)) { oindex = -(2 * oll / 3 - json.num); oul.css('left', toleft()); } movein = false; }); } }; banner_l.click(function () { move('+'); }); banner_r.click(function () { move('-'); }); btn.click(function (e) { e.stoppropagation(); movein = false; oindex = -oll / 3 - $(this).index(); move(); }); t.on("touchstart", function (e) { movein = false; oul.css('transition', 'transform 0ms'); t.roll_stop(); sx = e.originalevent.changedtouches[0].clientx; downtime = date.now(); _l = oul.position().left; _w = t.width() / json.num; }); t.on("touchmove", function (e) { e.preventdefault(); ex = e.originalevent.changedtouches[0].clientx - sx; if (ex > _w / 3) { oul.css('transform', 'translate3d(' + (_l + _w / 3 + 2 * _w / 3 * (1 - _w / 3 / ex)) + 'px, 0px, 0px)'); } else if (ex < -_w / 3) { oul.css('transform', 'translate3d(' + (_l - _w / 3 - 2 * _w / 3 * (1 - -_w / 3 / ex)) + 'px, 0px, 0px)'); } else { oul.css('transform', 'translate3d(' + (_l + ex) + 'px, 0px, 0px)'); } }); t.on("touchend", function (e) { outer = false; if (oindex >= 0 && ex > 0) { oindex = -1; outer = 1; } if (oindex <= -(oll - json.num) && ex < 0) { oindex = -(oll - json.num) + 1; outer = 2; } ex = e.originalevent.changedtouches[0].clientx - sx; if (ex >= _w / 3 || date.now() - downtime < 300 && ex > 30 || outer == 1) { move('+'); } else if (ex < -_w / 3 || date.now() - downtime < 300 && ex < -30 || outer == 2) { move('-'); } else { move(); } t.roll_start(); }); timer = setinterval(function () { move('-'); }, json.timer); suspend.hover(function () { t.roll_stop(); }, function () { t.roll_start(); }); t.fadeto("slow", 1); return this; }; $.fn.imgauto = function (co, fn) { fn = arguments[1] ? arguments[1] : {}; var fncall = function fncall(name, arg) { if (typeof fn[name] === 'function') fn[name](arg); }; $(this).each(function () { var t = $(this); t.css('opacity', 0); var img = new image(); img.src = t.attr('src'); var cover = t.attr('img-auto') == 'cover' || co ? true : false, _w = t.attr('width'), _h = t.attr('height'), box, i_w, i_h, b_w, b_h, t_w, t_h; if (_w && _h) { box = $(''); box.css({ width: _w, height: _h, "text-align": 'left', overflow: 'hidden' }); t.wrapall(box); } else { box = t.parent(); } function move() { if (img.width > 0 || img.height > 0) { fncall('imgautostart', img); t.css({ 'display': 'block', 'margin': 0 }).parent().css('overflow', 'hidden'); i_w = img.width; //原图宽 i_h = img.height; //原图高 b_w = box.width(); //父元素宽 b_h = box.height(); //父元素高 t_w = b_h / i_h * i_w; //实际显示的图片宽 t_h = b_w / i_w * i_h; //实际显示的图片高 if (i_w / i_h < b_w / b_h) { if (cover) { t.css({ 'width': '100%', 'height': 'auto' }).css('margin-top', -(t_h - b_h) / 2); } else { t.css({ 'width': 'auto', 'height': '100%' }).css('margin-left', (b_w - t_w) / 2); } } else { if (cover) { t.css({ 'width': 'auto', 'height': '100%' }).css('margin-left', -(t_w - b_w) / 2); } else { t.css({ 'width': '100%', 'height': 'auto' }).css('margin-top', (b_h - t_h) / 2); } } } else { settimeout(move); } fncall('callback', img); } move(); t.fadeto(2000, 1); var throttled = you.letter(move); $(window).resize(throttled); }); return this; }; })(jquery, window, document, undefined); you.rem(320); $(window).resize(function () { you.rem(320); }); //# sourcemappingurl=you.js.map //# sourcemappingurl=you.js.map