其次,我们来进行滚动区的样式的开发 。
但是这里我们要明确不同的是,我们除了单独的展示样式的开发外,我们还要主要对于过场动画效果的实现 。
import styled from "styled-components";import React, { FC } from "react";const Swiper = styled.div` overflow: hidden; position: relative;`;const SwiperContainer = styled.div` position: relative; width: auto; display: flex; align-item: center; justify-content: flex-start; transition: all 0.3s ease; -webkit-transition: all 0.3s ease; -moz-transition: all 0.3s ease; -o-transition: all 0.3s ease;`;const Swiper: FC< { direction?: 'horizontal' | 'vertical'; speed?: number; width: string; height: string; urls: string[]; }> = ({ direction = "horizontal", speed = 3, width = "", height = "", urls = []}) => { return (<Swiper style={{ width, height }}> <SwiperContainer id="swiper-container" style={{ height, // 根据轮播方向参数,调整flex布局方向 flexDirection: direction === "horizontal" ? "row" : "column", }} > </SwiperContainer> </Swiper>);}export default Swiper;在这里,我们给了他默认的宽度为auto,来实现整体宽度自适应 。而使用transition让后续的图片轮换可以有动画效果 。
最后,我们只需要将图片循环渲染在列表中即可 。
import styled from "styled-components";import React, { FC } from "react";const Swiper = styled.div` overflow: hidden; position: relative;`;const SwiperContainer = styled.div` position: relative; width: auto; display: flex; align-item: center; justify-content: flex-start; transition: all 0.3s ease; -webkit-transition: all 0.3s ease; -moz-transition: all 0.3s ease; -o-transition: all 0.3s ease;`;const SwiperSlide = styled.div` display: flex; align-item: center; justify-content: center; flex-shrink: 0;`;const Swiper: FC< { direction?: 'horizontal' | 'vertical'; speed?: number; width: string; height: string; urls: string[]; }> = ({ direction = "horizontal", speed = 3, width = "", height = "", urls = []}) => { return (<Swiper style={{ width, height }}> <SwiperContainer id="swiper-container" style={{ height, // 根据轮播方向参数,调整flex布局方向 flexDirection: direction === "horizontal" ? "row" : "column", }} > {urls.map((f: string, index: number) => ( <SwiperSlide style={{ ...styles }}> <img src=https://www.huyubaike.com/biancheng/{f} style={{ ...styles }} />
经验总结扩展阅读
- React +SpreadJS+Echarts 项目实战:在线报价采购系统
- 四十七 SpringCloud微服务实战——搭建企业级开发框架:【移动开发】整合uni-app搭建移动端快速开发框架-添加Axios并实现登录功能
- 怎么去除电脑上一个mcafee(怎么去除电脑上的小图标)
- 喜欢一个人在空间表白的说说100句 很甜很撩的表白情话
- 表示对某人心寒的句子看清一个人适合发朋友圈
- 一个鸡蛋两块五是什么意思网络用语
- 2023年农历6月搬家好吗
- 一个火龙果的热量是多少
- 每天一个番石榴的危害
- 两个6寸蛋糕和一个8寸哪个大