/** * Created by bcxin on 2016/12/13. */ if (!Function.prototype.bind) { Function.prototype.bind = function (oThis) { if (typeof this !== "function") { throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); } var aArgs = Array.prototype.slice.call(arguments, 1), fToBind = this, fNOP = function () { }, fBound = function () { return fToBind.apply(this instanceof fNOP && oThis ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments))); }; fNOP.prototype = this.prototype; fBound.prototype = new fNOP(); return fBound; }; } var adv = { DISTANCE: 0, DURATION: 1000, STEPS: 500, step: 0, interval: 0, timer: null, moved: 0, div: null, WAIT: 10000, init: function () { this.div = $(".msg")[0]; $(this.div).css("display", "block"); this.DISTANCE = -parseFloat($(this.div).css("bottom")); this.interval = this.DURATION / this.STEPS; this.step = this.DISTANCE / this.STEPS; this.moveUp(); this.moveDown(); }, moveUp: function () { this.timer = setInterval(this.moveStep.bind(this), this.interval); }, moveStep: function () { var bottom = parseFloat($(this.div).css("bottom")); this.div.style.bottom = bottom + this.step + "px"; this.moved++; if (this.moved == this.STEPS) { clearInterval(this.timer); this.timer = null; this.moved = 0; } }, moveDown: function () { if (this.timer == null) { $(this.div).fadeOut(500).css("bottom", -140 + "px"); } }, upView: function (title, data) { $(".msg .content h4").html(title); $(".msg .content span").html(data); } } window.onload = function () { var title = ""; var content = ""; $.ajax({ type: 'POST', url: baseUrl + "/auth/selectTipsByWebsite", async: false, success: function (json) { if (json.status != "0") { title = json.title; content = json.content; } }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert('请求失败'); } }); if (title != "" && content != "") { var bottom = parseFloat($(".msg").css("bottom")); if (bottom != 0 && bottom == -140) { adv.upView(title, content); adv.init(); } } }