当前位置: 首页 > article >正文

【CSS + ElementUI】更改 el-carousel 指示器样式且隐藏左右箭头

  1. 需求
    前三条数据以走马灯形式展现,指示器 hover 时可以切换到对应内容
    在这里插入图片描述

  2. 实现

<template>
   <div v-loading="latestLoading">
        <div class="upload-first" v-show="latestThreeList.length > 0">
            <el-carousel indicator-position="outside" height="180px" :autoplay="autoplay">
                <el-carousel-item v-for="(item) in latestThreeList" :key="item.id">
                    <div class="carousel-content" @click="handleDetail(item.id)">
                        <div class="first-title">
                            <span>{{ item.kind}}</span>
                        </div>
                        <div class="first-subtitle">
                            {{ item.title }}
                        </div>
                        <div class="first-summary">
                            {{ item.summary }}
                        </div>
                        <div class="first-time">
                            {{ item.createTime | formatTimer(item.createTime) }}
                        </div>
                    </div>
                </el-carousel-item>
            </el-carousel>
        </div>
    </div>
</template>
<script>
import { getList } from '@/api/xxx'
import { dateFormat } from '@/utils/utils'
export default {
	data(){
		return{
			latestLoading:false,
			latestThreeList: [],
			query:{
				pageNum:1,
				pageSize:10
			}
		}
	},
	mounted(){
		this.fetchData()
	},
	filters: {
        formatTimer(date) {
            return dateFormat(new Date(date),"yyyy-MM-dd")
        }
    },
	methods:{
		fetchData(){
			this.latestLoading = true
			getList(this.query).then(res=>{
				this.latestThreeList = res.data.slice(0, 3)
				this.latestLoading = false
			})
		},

		handleDetail(id){
			// 跳转到详情页
		}
	}
}
</script>
<style lang="less"> 
.upload-first {
        padding-bottom: 12px;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        align-self: stretch;
        border-radius: 10px;
        width: 976px;
        height: 184px;
        background: rgba(4, 106, 249, 0.05);
        margin: 24px auto;
        padding: 0 16px 0 0;

        .carousel-content:hover {
            color: #023fb5;
            cursor: pointer;
        }

        .first-title {
            display: flex;
            justify-content: flex-start;
            align-items: center;

            span {
                color: #2AC91C;
                font-family: "Source Han Sans CN";
                font-size: 12px;
                font-style: normal;
                font-weight: 400;
                line-height: 24px;
                border-radius: 0px 0px 20px 0px;
                background: #D6FFDE;
                padding: 8px 12px;
            }
        }

        .first-subtitle {
            color: #333;
            font-family: "Source Han Sans CN";
            font-size: 18px;
            font-style: normal;
            font-weight: 500;
            line-height: 24px;
            padding: 16px;
        }

        .first-subtitle:hover {
            color: #023fb5;
            cursor: pointer;
        }

        .first-summary {
            color: #666;
            font-family: "Source Han Sans CN";
            font-size: 16px;
            font-style: normal;
            font-weight: 400;
            line-height: 24px;
            padding: 0 16px;
            display: -webkit-box;
            /*! autoprefixer: off */
            -webkit-box-orient: vertical;
            /* autoprefixer: on */
            -webkit-line-clamp: 2;
            overflow: hidden;
            height: 48px;
        }

        .first-time {
            color: #666;
            font-family: "Source Han Sans CN";
            font-size: 14px;
            font-style: normal;
            font-weight: 350;
            line-height: 24px;
            text-align: right;
        }
    }
 
   
 .el-carousel__arrow { // 隐藏左右箭头
     display: none;
 }

 .el-carousel__indicator { // 改变指示器非选中下样式
     .el-carousel__button {
         width: 10px;
         height: 10px;
         border-radius: 50%;
         background-color: #f0f0f0;
         opacity: 1 !important;
     }
 }

 .el-carousel__indicator.is-active button { // 改变指示器选中时的样式
     background-color: #023FB5 !important;
     border-radius: 50%;
     outline: none;
     width: 8px;
     height: 8px;

     &:active {
         display: contents; // 解决左右箭头和指示器点击时有黑色边框
     }
 }
</style>
  1. 问题解决
    隐藏左右箭头,用 display: none;
    鼠标点击,出现黑边框,用display: contents;
    在这里插入图片描述
    在这里插入图片描述

  2. 最终效果
    在这里插入图片描述

  3. 数据结构

[
	{
		id:1,
		kind:'课题成果',
		title:'测试股1',
		summary:'测试股1',
		createTime:'2024-01-31 14:16:41'
	},
	{
		id:2,
		kind:'政策',
		title:'第二十条',
		summary:'摘要',
		createTime:'2024-02-04 15:16:41'
	}
]
  1. 日期格式化 @/utils/utils
/**
 * 日期格式化
 */
export function dateFormat(date, format) {
  format = format || "yyyy-MM-dd hh:mm:ss";
  if (date !== "Invalid Date") {
    let o = {
      "M+": date.getMonth() + 1, //month
      "d+": date.getDate(), //day
      "h+": date.getHours(), //hour
      "m+": date.getMinutes(), //minute
      "s+": date.getSeconds(), //second
      "q+": Math.floor((date.getMonth() + 3) / 3), //quarter
      S: date.getMilliseconds() //millisecond
    };
    if (/(y+)/.test(format))
      format = format.replace(
        RegExp.$1,
        (date.getFullYear() + "").substr(4 - RegExp.$1.length)
      );
    for (let k in o)
      if (new RegExp("(" + k + ")").test(format))
        format = format.replace(
          RegExp.$1,
          RegExp.$1.length === 1 ?
          o[k] :
          ("00" + o[k]).substr(("" + o[k]).length)
        );
    return format;
  }
  return "";
}

http://www.kler.cn/a/228083.html

相关文章:

  • Centos 7.5 安装 NVM 详细步骤
  • 基于ESP8266 开发板(MCU)遥控小车
  • PHP三级分类数据处理
  • eslint报错文档大量红色报错符号 不自动修正
  • ERP 系统架构的设计与实践总结
  • 课时14:变量基础_变量定义
  • 蓝桥杯第八届省赛题笔记------基于单片机的电子钟程序设计与调试
  • 【华为】GRE VPN 实验配置
  • 彻底学会系列:一、机器学习之线性回归
  • scikit-learn 1.3.X 版本 bug - F1 分数计算错误
  • 【MATLAB源码-第135期】基于matlab的变色龙群优化算法CSA)机器人栅格路径规划,输出做短路径图和适应度曲线。
  • 跟着cherno手搓游戏引擎【20】混合(blend)
  • 全流程机器视觉工程开发(四)PaddleDetection C++工程化应用部署到本地DLL以供软件调用
  • 线性表 —— 数组、栈、队、链表
  • 【SparkML实践7】特征选择器FeatureSelector
  • Redis实现:每个进程每30秒执行一次任务
  • Tomcat组件架构与数据流
  • 04.PostgreSQL多表查询
  • ffmpeg的使用,安装,抽帧,加水印,截图,生成gif,格式转换,抓屏等
  • 简单介绍Spring Security 的认证机制和授权机制