>  기사  >  위챗 애플릿  >  WeChat 애플릿 구성 요소 윤곽 예시 공유

WeChat 애플릿 구성 요소 윤곽 예시 공유

小云云
小云云원래의
2018-01-06 10:48:002952검색

이 글은 WeChat 애플릿 구성 요소 윤곽의 자세한 예에 대한 관련 정보를 주로 소개합니다. 도움이 필요한 친구들이 참고할 수 있기를 바랍니다.

위챗 미니 프로그램 구성 요소 마키 예시 상세 설명

1. 마키 태그

html에는 마키 효과를 낼 수 있는 마키 태그가 있지만 미니 프로그램에는 없기 때문에 반드시 구현해야 합니다. 여기서 CSS3 애니메이션 구현을 사용해 보세요.

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:&#39;hello world&#39;
}

그리고 이상한 점은 marqueeWidth가 @keyframes에 전달되는 변수라는 것입니다. 변수는 인라인으로 설정되며 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)=>{// 保留,根据文字长度设置时间
  return this.getWidth()/10;
 }
}

위는 컴포넌트 패키지입니다. R5. re

// wxml
<include src="../component/marquee/marquee.wxml" />
// wxss
@import "../component/marquee/marquee.wxss";
// js
import marquee from &#39;../component/marquee/marquee.js&#39;;

var options = Object.assign(marquee, {
 data: {
  motto: &#39;Hello World&#39;,
  userInfo: {},
  marquee: { text: &#39;你好,中国!hello,world!&#39; }
 },
 onLoad: function () {
  // ...

  const str = this.data.marquee.text;
  const width = this.getWidth(str);
  console.log(&#39;width&#39;,width);
  this.setData({ [`${&#39;marquee&#39;}.width`]: width });
 }
});
Page(options);

사용 관련 추천 :

Hhtml의 Marquee 라벨 상세 소개


Marquee 라벨을 통해 Marquee 라벨 사용법

을 요약하여 스크롤 효과의 순수한 롤링 효과 완성 HTML 코드

위 내용은 WeChat 애플릿 구성 요소 윤곽 예시 공유의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.