×

React小应用:介绍实现轮播图的应用

作者:Web前端之家2022.08.25来源:Web前端之家浏览:601评论:0
关键词:React

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;
}

大家可以去试试!

您的支持是我们创作的动力!
温馨提示:本文作者系Web前端之家 ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://www.jiangweishan.com/article/react20220825.html

网友评论文明上网理性发言 已有0人参与

发表评论:

最新留言

  • 访客

    sddddddddddddddVS的vVSVS但是v方法v方法v发v方法v发v发v方不方便德文法文...

  • 没人发言

    鸡肋的功能...

  • 23b

    这个你应该加群找群主才对吧...

  • 访客

    大佬,能提供能一下提取图片中的文字工具的源码吗,感谢...

  • qdxx

    SEO原创还可以的,新手学习下。...

  • Web前端之家

    已处理!...

  • 程序员路灯

    贵站友链已添加名称:程序员路灯地址:http://www.eqishare.com...

  • Web前端之家

    可以加群讨论...

首页|JavaScript|HTML|HTML4|HTML5|CSS3|开发工具|性能优化|移动开发|前端教程|性能优化|开发工具|酷站欣赏|UI设计|前端教程

Copyright © 2022 Web前端之家(www.jiangweishan.com) 版权所有 All Rights Reserved.
粤ICP备12067512号-1

Copyright Your WebSite.Some Rights Reserved.

Powered By Z-BlogPHP 1.7.2