小程序-公告滚动

 

<view class="bg_box icon_nav_box" style="margin-top: -70rpx;position: relative;">
    <view class="flex flex_y_center">
            <view class="c_red f32" style="font-style: italic;flex-shrink:0 ;">最新公告</view>
            <view class="c_colum" style="line-height: 60rpx;height: 60rpx;overflow-y: hidden;position: relative;"> 
              <view class="notice_main" style="top: {{notice_top}}rpx;">
              <block wx:for="{{notice_list}}">
                <view  class="ml15 lineText">{{item.title}}</view>
              </block>
              </view>
            </view>
    </view>
</view>


.icon_nav_box .item{flex: 1;}
.icon_nav_box .icon{width: 100rpx;}
noticeScoll(){//公告滚动
    let that = this;
    let curindex = 0;
    setInterval(() => {
      let top = that.data.notice_top;
      let notice_list = that.data.notice_list;
      if(curindex < notice_list.length-1){
        curindex = curindex+1;
        that.setData({
          notice_top: top - 60
        })
      }else{
        curindex = 0;
        that.setData({
          notice_top: 0,
        })
      }
    }, 3000);

  },


 data: {
    notice_list:[
        {title:"商城上线啦农资上线啦1",},
        {title:"商城上线啦农资商城上线啦农资商城上线啦2",},
        {title:"商城上线啦资商城上线啦农资商城上线啦3",},
        {title:"商城上线啦啦农资商城上线啦4",},
        {title:"商城上上线啦5",},
        {title:"商城上线啦农啦农资商城上线啦6",},
    ],
    notice_top:0,
},

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个微信小程序文字公告栏的代码示例: ``` <view class="notice"> <text class="notice-text">{{notice}}</text> <text class="notice-more">更多</text> </view> ``` 其中,`.notice` 和 `.notice-text` 是样式类名,可以根据需要自行修改;`{{notice}}` 是公告文字的数据绑定,需要在对应的 Page 或 Component 中定义;`notice-more` 是一个“更多”按钮,可以根据需要添加或删除。 在对应的样式文件中,可以添加如下样式: ``` .notice { background-color: #f5f5f5; height: 40rpx; line-height: 40rpx; text-align: center; overflow: hidden; position: relative; } .notice-text { font-size: 24rpx; color: #333; margin: 0 30rpx; white-space: nowrap; animation: noticeMove 10s linear infinite; } .notice-more { font-size: 24rpx; color: #999; position: absolute; right: 20rpx; top: 50%; transform: translateY(-50%); } @keyframes noticeMove { 0% { transform: translateX(0); -webkit-transform: translateX(0); } 100% { transform: translateX(-100%); -webkit-transform: translateX(-100%); } } ``` 其中,`animation` 属性定义了公告文字滚动的动画效果,可以自行修改动画时长和动画函数;`@keyframes` 定义了动画的具体实现,可以根据需要自行修改。 在对应的 Page 或 Component 中,需要定义公告文字的数据绑定,例如: ``` Page({ data: { notice: '欢迎使用微信小程序!' } }) ``` 以上就是一个简单的微信小程序文字公告栏的代码示例,可以根据需要进行修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值