網站首頁 編程語言 正文
本文實例為大家分享了React實現輪播圖效果的具體代碼,供大家參考,具體內容如下
效果:
輪播功能用到了react-slick組件,安裝:
npm install react-slick --save
npm install slick-carousel
安裝完后需要在使用輪播圖的頁面上導入css文件:
import Slider from 'react-slick';
import 'slick-carousel/slick/slick.css';
import 'slick-carousel/slick/slick-theme.css';
swiper.js
import React, { Component } from 'react';
import Slider from 'react-slick';
import 'slick-carousel/slick/slick.css';
import 'slick-carousel/slick/slick-theme.css';
?
export default class SimpleSlider extends Component {
? ? render() {
? ? ? ? const settings = {
? ? ? ? ? ? dots: true,
? ? ? ? ? ? dotsClass:'slick-dots1',//自定義指示器的樣式
? ? ? ? ? ? // dots: {'dot-style':String},
? ? ? ? ? ? infinite: true,
? ? ? ? ? ? speed: 500,
? ? ? ? ? ? slidesToShow: 1,
? ? ? ? ? ? slidesToScroll: 1,
? ? ? ? ? ? height:500
? ? ? ? };
? ? ? ? return (
? ? ? ? ? ? <div style={{margin:'50px 12px 40px 12px'}}>
? ? ? ? ? ? ? ? <h2> Single Item</h2>
? ? ? ? ? ? ? ? <Slider {...settings}>
? ? ? ? ? ? ? ? ? ? <div>
? ? ? ? ? ? ? ? ? ? ? ? <h3>1</h3>
? ? ? ? ? ? ? ? ? ? ? ? <div style={{background:'#25f5f5',height:'160px'}}>sdfkjsdlfjldskfjlksjdf</div>
? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? <div>
? ? ? ? ? ? ? ? ? ? ? ? <h3>2</h3>
? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? <div>
? ? ? ? ? ? ? ? ? ? ? ? <h3>3</h3>
? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? <div>
? ? ? ? ? ? ? ? ? ? ? ? <h3>4</h3>
? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? <div>
? ? ? ? ? ? ? ? ? ? ? ? <h3>5</h3>
? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? <div>
? ? ? ? ? ? ? ? ? ? ? ? <h3>6</h3>
? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? </Slider>
? ? ? ? ? ? </div>
? ? ? ? );
? ? }
}
swiper.css
//輪播圖下方dot樣式
.slick-dots1
{
? position: absolute;
? bottom: -25px;
? display: block;
? width: 100%;
? padding: 0;
? margin: 0;
? list-style: none;
? text-align: center;
}
.slick-dots1 li
{
? position: relative;
? display: inline-block;
? width: 20px;
? height: 20px;
? margin: 0 5px;
? padding: 0;
? cursor: pointer;
}
.slick-dots1 li button
{
? font-size: 0;
? line-height: 0;
? display: block;
? width: 20px;
? height: 20px;
? padding: 5px;
? cursor: pointer;
? color: transparent;
? border: 0;
? outline: none;
? background: transparent;
}
.slick-dots1 li button:hover,
.slick-dots1 li button:focus
{
? outline: none;
}
.slick-dots1 li button:hover:before,
.slick-dots1 li button:focus:before
{
? opacity: 1;
}
//未選中時的樣式
.slick-dots1 li button:before
{
? font-family: 'slick';
? font-size: 8px;
? line-height: 8px;
? position: absolute;
? top: 0;
? left: 0;
? width: 20px;
? height: 8px;
? content: '?';
? text-align: center;
? //opacity: .25;
? color: #CCCCCC;
? -webkit-font-smoothing: antialiased;
? -moz-osx-font-smoothing: grayscale;
}
//選中的樣式
.slick-dots1 li.slick-active button:before
{
? //opacity: .75;
? color: #2183E2;
? background-color: #2183E2;
? border-radius: 5px;
}
原文鏈接:https://blog.csdn.net/liuye066/article/details/119417699
相關推薦
- 2022-04-11 C++17之std::any的具體使用_C 語言
- 2022-07-12 ERROR:ORA-12543: TNS:destination host unreachable
- 2021-12-02 深入了解c語言的循環語句_C 語言
- 2023-04-22 python的open函數使用案例代碼_python
- 2022-11-27 C語言移除元素的三種思路講解_C 語言
- 2023-01-05 C#不提升自己程序的權限實現操作注冊表_C#教程
- 2022-12-14 Jetpack?Compose?雙指拖拽實現詳解_Android
- 2023-01-23 使用Docker部署Dashdot服務器儀表盤的步驟_docker
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支