自己实现一个时间轴-Taro小程序相关

一个时间轴。

最近在做项目的时候,遇到了物流展示时间轴,记录一下吼吼吼

taro—ui本身给我们提供了时间轴taroUI官方文档-时间轴

但素个人用起来taroui始终有些不灵活,于是乎自己手码,

数据是动态渲染的,为了方便复用,看得更清楚。只贴了一小段代码,

flex+100%布局;小圆点是我拿css画出来的。

想加icon图标也是同样的道理。

     <View className='ys-list' key='logistic'>
          <View className='des-time'>
            <Text className=''>{day}</Text>
            <Text className=''>{dayTime}</Text>
          </View>
          <View className='des-mes'>
            <View className='list-dot'>
              <View className='dot' />
            </View>
            <Text className=''>{list.content}</Text>
          </View>
     </View>

这里使用的是scss:

    .ys-list {
      width: 100%;
      display: flex;
      flex-direction: row;
      .des-time {
        width: 10%;
        font-size: 22px;
        display: flex;
        flex-direction: column;
        text-align: right;
        padding-right: 40px;
        color: #888888;
      }
      .des-mes {
        border-left: 2px solid #e6e6e6;
        padding-left: 40px;
        width: 80%;
        display: flex;
        flex-direction: column;
        font-size: 26px;
        position: relative;
        padding-bottom: 80px;
        .list-dot {
          width: 48px;
          height: 48px;
          line-height: 48px;
          position: absolute;
          top: -9px;
          left: -24px;
          display: flex;
          align-items: center;
          justify-content: center;
          .dot {
            width: 15px;
            height: 15px;
            border-radius: 100%;
            background-color: #dddddd;
          }
        }
      }
    }


例图

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
要在Taro小程序实现跑马灯效果,你可以按照以下步骤进行操作: 1. 在Taro小程序的页面组件中,使用`@tarojs/components`中的`View`组件创建一个容器,用于显示跑马灯内容。 2. 使用CSS设置容器的宽度、高度、背景颜色等样式。 3. 在容器内部创建一个`ScrollView`组件,用于实现滚动效果。设置`scroll-x`属性为`true`,表示横向滚动。 4. 在`ScrollView`组件内部,创建一个`View`组件作为内容容器。在该容器内部创建多个`Text`组件,用于显示跑马灯的文本内容。 5. 使用CSS设置文本内容的样式,如字体大小、颜色等。 6. 使用定时器(`setInterval`)控制文本内容的滚动,可以通过改变内容容器的`transform`属性来实现滚动效果。 以下是一个简单的示例代码: ```jsx import Taro, { useEffect, useState } from '@tarojs/taro'; import { View, ScrollView, Text } from '@tarojs/components'; function Marquee() { const [textList, setTextList] = useState(['文本1', '文本2', '文本3']); // 跑马灯文本内容 useEffect(() => { const timer = setInterval(() => { setTextList(prevList => { const lastText = prevList[prevList.length - 1]; return [lastText, ...prevList.slice(0, prevList.length - 1)]; }); }, 2000); return () => { clearInterval(timer); }; }, []); return ( <View className="marquee-container"> <ScrollView scrollX className="scroll-view"> <View className="content"> {textList.map((text, index) => ( <Text key={index} className="text">{text}</Text> ))} </View> </ScrollView> </View> ); } export default Marquee; ``` 在上述代码中,我们通过`useState`来管理跑马灯的文本内容。通过`useEffect`和定时器实现文本内容的滚动效果。你可以根据需要修改样式和文本内容,以适应你的实际需求。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值