最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序組件 marquee實例詳解

 更新時間:2017年06月23日 11:54:27   作者:武安長空  
這篇文章主要介紹了微信小程序組件 marquee實例詳解的相關(guān)資料,需要的朋友可以參考下

微信小程序組件 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)文章

最新評論

唐河县| 五原县| 瑞安市| 泰州市| 肇州县| 沂南县| 宁明县| 山西省| 台州市| 法库县| 台中市| 双流县| 连江县| 泽州县| 融水| 怀安县| 浦江县| 白朗县| 济阳县| 青川县| 乐东| 阿合奇县| 广安市| 四子王旗| 馆陶县| 沂水县| 盱眙县| 宾川县| 台湾省| 惠东县| 抚宁县| 巫溪县| 恩平市| 扎赉特旗| 黄龙县| 临城县| 民丰县| 抚州市| 通河县| 马尔康县| 无棣县|