這篇“微信小程序組件marquee如何用”文章的知識點大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細,步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“微信小程序組件marquee如何用”文章吧。
讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:空間域名、網(wǎng)絡(luò)空間、營銷軟件、網(wǎng)站建設(shè)、婺源網(wǎng)站維護、網(wǎng)站推廣。
微信小程序組件 marquee實例詳解
1. marquee標簽
html是有marquee標簽的,可以實現(xiàn)跑馬燈效果,但小程序沒有,所以要實現(xiàn)。這里考慮使用css3的animation實現(xiàn)。
html的marquee是這樣使用的。
<marquee direction="left" behavior="scroll" scrollamount="1" scrolldelay="0" loop="-1" width="200" height="50" bgcolor="#0099FF" hspace="10" vspace="10"> hello world </marquee>
2. wxml
<view class="marquee_container" style="--marqueeWidth--:{{-marquee.width}}em"> <view class="marquee_text">{{marquee.text}}</view> </view>
傳入wxml的是個json對象
marquee:{ width:12, text:'hello world' }
而那個奇怪的--marqueeWidth是給@keyframes傳的變量。內(nèi)聯(lián)設(shè)置變量,css文件中也可以獲取到該變量。
3. wxss
@keyframes around { from { margin-left: 100%; } to { margin-left: var(--marqueeWidth--);// var接受傳入的變量 } } .marquee_container{ background-color: #0099FF; height: 1.2em; position: relative; width: 100%; } .marquee_container:hover{ animation-play-state: paused; // 不起作用 } .marquee_text{ display: inline-block; white-space: nowrap; animation-name: around; animation-duration: 5s; animation-iteration-count: infinite; animation-timing-function:linear; }
4. js
export default { getWidth:(str)=>{ return [].reduce.call(str, (pre, cur, index, arr) => { if (str.charCodeAt(index) > 255) {// charCode大于255是漢字 pre++; } else { pre += 0.5; } return pre; }, 0); }, getDuration:(str)=>{// 保留,根據(jù)文字長度設(shè)置時間 return this.getWidth()/10; } }
以上是組件的封裝。
5. 使用
// wxml <include src="../component/marquee/marquee.wxml" /> // wxss @import "../component/marquee/marquee.wxss"; // js import marquee from '../component/marquee/marquee.js'; var options = Object.assign(marquee, { data: { motto: 'Hello World', userInfo: {}, marquee: { text: '你好,中國!hello,world!' } }, onLoad: function () { // ... const str = this.data.marquee.text; const width = this.getWidth(str); console.log('width',width); this.setData({ [`${'marquee'}.width`]: width }); } }); Page(options);
以上就是關(guān)于“微信小程序組件marquee如何用”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對大家有幫助,若想了解更多相關(guān)的知識內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)站名稱:微信小程序組件marquee如何用
分享網(wǎng)址:http://m.rwnh.cn/article2/gspeic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號、品牌網(wǎng)站制作、云服務(wù)器、網(wǎng)站策劃、App設(shè)計、網(wǎng)頁設(shè)計公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)