這篇“微信小程序組件marquee如何用”文章的知識(shí)點(diǎn)大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價(jià)值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“微信小程序組件marquee如何用”文章吧。

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡(jiǎn)單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:空間域名、網(wǎng)絡(luò)空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、婺源網(wǎng)站維護(hù)、網(wǎng)站推廣。
微信小程序組件 marquee實(shí)例詳解
1. marquee標(biāo)簽
html是有marquee標(biāo)簽的,可以實(shí)現(xiàn)跑馬燈效果,但小程序沒有,所以要實(shí)現(xiàn)。這里考慮使用css3的animation實(shí)現(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的是個(gè)json對(duì)象
marquee:{
width:12,
text:'hello world'
}而那個(gè)奇怪的--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ù)文字長(zhǎng)度設(shè)置時(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: '你好,中國(guó)!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)容對(duì)大家有幫助,若想了解更多相關(guān)的知識(shí)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)站名稱:微信小程序組件marquee如何用
分享網(wǎng)址:http://chinadenli.net/article2/gspeic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、品牌網(wǎng)站制作、云服務(wù)器、網(wǎng)站策劃、App設(shè)計(jì)、網(wǎng)頁(yè)設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
移動(dòng)網(wǎng)站建設(shè)知識(shí)