From 6d0d7ca6d0c503872ecd8d8b6557ea32d7452747 Mon Sep 17 00:00:00 2001 From: binbin0314 Date: Mon, 2 Aug 2021 18:23:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=91=E9=A9=AC=E7=81=AF=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index 0400fa3..1901374 100644 --- a/index.html +++ b/index.html @@ -25,9 +25,11 @@
-
-
- +
+ +
+
@@ -101,7 +103,7 @@ }).then(function(res){ const { success, code, data, msg } = res; if (success && code === 200) { - if(data.content !== this.content){ + if(data.content !== that.content){ that.setDate(data.content) } } else { @@ -112,28 +114,36 @@ // 界面渲染 setDate(res) { - if(res !== this.content){ - this.content = res + var box = this.dom.querySelector('.box'); //获取标签 + var oTxt = this.dom.querySelector('.txt'); //获取标签 + this.content = res + oTxt.innerHTML = this.content + // 设置宽度 + if(res.length < 88){ + oTxt.style.width = "70%" + }else{ + oTxt.style.width = "140%" } + var textLeft = 0 - var oTxt = this.dom.querySelector('.txt'); //获取标签 if(this.divWidth === 0) { this.divWidth = oTxt.offsetWidth + textLeft = box.offsetWidth - 1 } - oTxt.innerHTML = res var that = this clearInterval(this.timeId); this.timeId = null if(!this.timeId) { this.timeId = setInterval(function (){ //通过定时器重复动作 - oTxt.style.position = 'absolute'; - if(-textLeft < that.divWidth + 30){ + // oTxt.style.position = 'absolute'; + if(textLeft > -oTxt.offsetWidth && textLeft < box.offsetWidth){ textLeft--; var leftPX = textLeft + 'px'; oTxt.style.transform = `translate3d(${leftPX},0,0)` } else { - clearInterval(this.timeId); + textLeft = box.offsetWidth - 1 + // clearInterval(this.timeId); } },20) }