var vm = new Vue({ el: "#app", data: { flag: false, tan: false, X: "", Xend: "" }, methods: { befEnt: function(el) { el.style.transform = "translate(0,0)"; }, enter: function(el, done) { el.offsetWidth; this.X = Math.floor(Math.random() * 1000) + "px"; var num = parseInt(this.X); el.style.transform = "translate(" + this.X + ",490px)"; el.style.transition = "all 1s"; if (num >= 400 && num <= 570) { this.tan = false; done(); } else { this.tan = true; setTimeout(function() { this.Xend = Math.floor(Math.random() * 1000) + "px"; el.style.transform = "translate(" + this.Xend + ",0)"; el.style.transition = "all 1s"; done(); }, 1000); } }, aftEnt: function(el) { if (this.tan) { this.flag = false; this.tan = false; this.X = ""; this.Xend = ""; setTimeout(function() { alert("失败"); }, 1300); } else { this.flag = false; this.X = ""; this.Xend = ""; setTimeout(function() { alert("成功"); }, 300); } } } });
|