var tabs = function (el, pre, next, position) { this.$el = $(el); this.$pre = $(pre); this.$next = $(next); this.childrens = this.$el.children() if (position) { this.postiton = position } else { this.postiton = [] for (var i = 0; i < this.childrens.length; i++) { this.postiton.push($(this.childrens[i]).outerwidth(true) * i); } } }; tabs.prototype = { start: function () { this.current = 0; this.bindpre(); this.bindnext(); }, bindpre: function () { var self = this; this.$pre.on("click", function (e) { e.preventdefault(); var next = self.current - 1; if (next < 0) { return; } self.current = next; self.startanimation(); }) }, bindnext: function () { var self = this; this.$next.on("click", function (e) { e.preventdefault(); var next = self.current + 1; console.log(next, next >= self.postiton.length); if (next >= self.postiton.length) { return; } self.current = next; self.startanimation(); }) }, startanimation: function () { var self = this; var left = -this.postiton[this.current] this.$el.css({ left: left + 'px' }) } } $(function () { try { var w = $("#other_honer").outerwidth(true); var num = $("#other_honer").attr("data-num"); $("#other_honer").css("width", w * parseint(num) + "px"); var othertab = new tabs('#other_honer', '.other-honer-box .left', '.other-honer-box .right'); othertab.start(); } catch (e) { console.log(e); } (function () { try { var position = []; var w = $("#home-time-box").outerwidth(true); var wss = $(".page-dot").outerwidth(true); var num = math.ceil(w / wss); for (var i = 0; i < num; i++) { var cc = wss * i; cc = cc > (w - 1073) ? w - 1073 : cc; position.push(cc); } console.log(position) var honertab = new tabs('#home-time-box', '.honer-time-page .left', '.honer-time-page .right', position); honertab.start(); } catch (e) { console.log(e); } $("#home-time-box li").on("click", function (e) { e.preventdefault(); var year = $(this).attr("data-year"); $("#home-time-box li").removeclass("cur"); $(this).addclass("cur"); $("#home-time-box li img").attr("src", "/static/core-image/poi.png"); $(this).find("img").attr("src", "/static/core-image/poi-selected.png"); $(".honer-intro-box").hide(600); $(".honer-intro-box-" + year).show(600); }) })(); $(".other-honer-box .left").mouseenter(function (e) { e.preventdefault(); $(this).attr("src", "/static/core-image/honer-left-big-hover.png"); }); $(".other-honer-box .right").mouseenter(function (e) { e.preventdefault(); $(this).attr("src", "/static/core-image/honer-right-big-hover.png"); }); $(".other-honer-box .left").mouseleave(function (e) { e.preventdefault(); $(this).attr("src", "/static/core-image/honer-left-big.png"); }); $(".other-honer-box .right").mouseleave(function (e) { e.preventdefault(); $(this).attr("src", "/static/core-image/honer-right-big.png"); }); $(".page-dot ul li").mouseenter(function (e) { e.preventdefault(); $(this).find("img").attr("src", "/static/core-image/poi-selected.png"); }); $(".page-dot ul li").mouseleave(function (e) { e.preventdefault(); if ($(this).hasclass("cur")) { return; } $(this).find("img").attr("src", "/static/core-image/poi.png"); }); $(".honer-time-page .left").mouseenter(function (e) { e.preventdefault(); $(this).attr("src", "/static/core-image/poi-left-allow.png"); }); $(".honer-time-page .right").mouseenter(function (e) { e.preventdefault(); $(this).attr("src", "/static/core-image/poi-right-allow.png"); }); $(".honer-time-page .left").mouseleave(function (e) { e.preventdefault(); $(this).attr("src", "/static/core-image/poi-left.png"); }); $(".honer-time-page .right").mouseleave(function (e) { e.preventdefault(); $(this).attr("src", "/static/core-image/poi-right.png"); }); })