網(wǎng)站首頁 編程語言 正文
本文實(shí)例為大家分享了React實(shí)現(xiàn)輪播圖效果的具體代碼,供大家參考,具體內(nèi)容如下
效果:
輪播功能用到了react-slick組件,安裝:
npm install react-slick --save
npm install slick-carousel
安裝完后需要在使用輪播圖的頁面上導(dǎo)入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;
}
//未選中時(shí)的樣式
.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
相關(guān)推薦
- 2022-07-02 C#并行編程之Task同步機(jī)制_C#教程
- 2023-05-21 詳解在Anaconda環(huán)境下Python安裝pydot與graphviz的方法_python
- 2022-05-22 Python?IO文件管理的具體使用_python
- 2022-05-06 一起來看看C++STL容器之string類_C 語言
- 2023-05-15 shell參數(shù)換行與shell輸出換行的方法實(shí)例_linux shell
- 2022-07-27 PostgreSQL出現(xiàn)死鎖該如何解決_PostgreSQL
- 2022-11-17 Android復(fù)選框CheckBox與開關(guān)按鈕Switch及單選按鈕RadioButton使用示例詳
- 2022-06-29 Python中bytes和str的區(qū)別與聯(lián)系詳解_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支