<marquee direction="left" behavior="scroll" scrollamount="1" scrolldelay="0" loop="-1" width="200" height="50" bgcolor="#0099FF" hspace="10" vspace="10"> hello world </marquee>
<view class="marquee_container" style="--marqueeWidth--:{{-marquee.width}}em">
<view class="marquee_text">{{marquee.text}}</view>
</view>
marquee:{
width:12,
text:'hello world'
}
@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;
}
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;
}
}
// 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);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有