单行文字横向循环滚动

单行文字循环滚动

已把该功能以组件的形式抽离出来,根据需求可以更改滚动的字体,背景颜色,以及字体颜色
注:因为这是一个用Taro写的小程序,大家看的时候可以忽略里面引入的东西以及标签,着重看render里面的代码

动画实现:

import { View } from '@tarojs/components'
import { connect } from '@tarojs/redux'
import Taro from '@tarojs/taro'
import QyIcon from '@/components/qy-icon'
import styles from './index.scss'

@connect(({ app }) => ({ app }))
export default class ShufflingAnnouncement extends Taro.Component {
    static defaultProps = {
        content: '默认轮播公告内容打不打吧大的啊了发生',
        bgc: 'red',
        col: '#000000'
    }

    render() {
        const { content, bgc, col } = this.props
        return (
            <View className={styles['marquee']} style={{ backgroundColor: `${bgc}` }}>
                <QyIcon name='notice' color={col} size='40rpx' />
                <View className={styles['wai']}>
                    <View className={styles['text']} style={{ color: `${col}` }}>{content}</View>
                </View>
            </View>
        )
    }
}

css

.marquee {
  display: flex;
  align-items: center;
  width: 670px;
  height: 60px;
  margin: 0 auto;
  padding-left: 20px;
  .wai {
    width: 630px;
    overflow: hidden;
    padding-left: 20px;
    margin-left: 20px;
    .text {
      white-space: nowrap;
      display: inline-block;
      animation: wordsLoop 10s linear infinite normal;
    }
    @keyframes wordsLoop {
      0% {
        transform: translateX(500px);
        -webkit-transform: translateX(500px);
      }
      100% {
        transform: translateX(-100%);
        -webkit-transform: translateX(-100%);
      }
    }
  }
}

使用

import ShufflingAnnouncement from '' //根据自己存放的路径引入
render(){
	return (
		<ShufflingAnnouncement bgc={'blue'} col={'white'} />
	)
}

结束语

该功能还可以完善,支持可配置ICON等等

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值