文字滚动效果组件和按钮组件

今天和大家分享一个vue中好用的组件,是我自己写的,大家也可以自己改,就是文字的循环滚动效果,如下图,文字会向左移动,结束之后也会有一个循环,还有一个按钮组件,基本框架写的差不多了已经,大家可以看着改,如果使用直接拿走就行了

文字: 

相应效果图: 

相应使用方法:

章节使用组件就可以了 

文字滚动源代码:

大家使用只需要改上面的文字就行了,字体样式大家在对应元素的css当中写 

<template><div class="announcement"><!-- 头部图标和标题 --><div class="announcement_icon"><span class="icon iconfont">&#xe506;</span></div><div class="announcement_title">最新公告</div><!-- 滚动区域 --><div class="announcement_text"><!-- 添加滚动容器 --><div ref="scrollDiv" class="scroll-container"><!-- 双份相同内容实现无缝循环 --><div ref="scrollBegin" class="scroll-content"><span class="pad_right">{{ announcementText }}</span></div><div ref="scrollEnd" class="scroll-content"></div></div></div></div>
</template><script setup>
import { ref, onMounted } from 'vue'const announcementText = `在当今数字化时代,人工智能(AI)已经逐渐渗透到我们生活的方方面面。从智能家居设备到自动驾驶汽车,AI的应用正在不断扩展和深化。随着技术的不断进步,AI的能力也在不断提升,它不仅能够处理复杂的计算任务,还能模拟人类的思维和行为模式。 AI的发展带来了许多机遇和挑战。一方面,它极大地提高了生产效率,改善了人们的生活质量。例如,医疗领域中,AI可以帮助医生更准确地诊断疾病,提供个性化的治疗方案。另一方面,AI也引发了一些伦理和社会问题,如隐私保护、数据安全和就业结构的变化。这些问题需要我们在技术发展的过程中不断探索和解决。未来,AI 将继续在更多领域发挥重要作用。教育、金融、交通等行业都将受益于 AI的创新应用。同时,随着 AI 技术的普及,人们对其理解和接受度也在提高。这将有助于推动 AI更好地服务于社会,为人类创造更多的福祉。` // 简化的公告文本const scrollDiv = ref(null)
const scrollBegin = ref(null)
const scrollEnd = ref(null)
let MyMar = null
const speed = 10 // 滚动速度(数值越大越慢)const initMarquee = () => {if (!scrollBegin.value || !scrollEnd.value || !scrollDiv.value) return// 克隆内容实现无缝滚动scrollEnd.value.innerHTML = scrollBegin.value.innerHTMLconst marquee = () => {if (!scrollDiv.value) return// 判断滚动位置重置if (scrollDiv.value.scrollLeft >= scrollBegin.value.offsetWidth) {scrollDiv.value.scrollLeft = 0} else {scrollDiv.value.scrollLeft += 1}}// 设置滚动间隔MyMar = setInterval(marquee, speed)// 鼠标控制scrollDiv.value.addEventListener('mouseenter', () => clearInterval(MyMar))scrollDiv.value.addEventListener('mouseleave', () => {MyMar = setInterval(marquee, speed)})
}onMounted(() => {initMarquee()
})
</script><style scoped>
/* 基础布局 */
.announcement {display: flex;align-items: center;height: 78px;background: #f8f9fa;padding: 0 20px;z-index: -10;
}/* 图标样式 */
.announcement_icon {color: #338bcd;margin-right: 10px;
}
.announcement_icon .iconfont {font-size: 29px;
}/* 标题样式 */
.announcement_title {font-size: 22px;color: #006fc1;white-space: nowrap;margin-right: 20px;
}/* 滚动区域 */
.announcement_text {width: 100%;height: 100%;line-height: 78px;overflow: hidden;position: relative;
}.scroll-container {display: inline-flex; /* 关键:保持内容横向排列 */white-space: nowrap; /* 禁止文字换行 */position: absolute;animation: marquee 40s linear infinite; /* 备用CSS动画 */z-index: 100;
}.scroll-content {display: inline-block;padding-right: 50px; /* 内容间隔 */
}/* 鼠标悬停暂停 */
.scroll-container:hover {animation-play-state: paused;
}/* 备用CSS动画 */
@keyframes marquee {0% {transform: translateX(0);}100% {transform: translateX(-50%);}
}/* 响应式适配 */
@media (max-width: 768px) {.announcement {padding: 0 10px;height: 60px;}.announcement_title {font-size: 16px;margin-right: 10px;}.scroll-content {font-size: 14px;}
}
</style>

 

按钮:

效果图:

相应使用方法:

<el-row>
<MButton type="" >普通</MButton>
<MButton type="primary">主要</MButton>
<MButton type="success">成功</MButton>
<MButton type="info">信息</MButton>
<MButton type="warning">警告</MButton>
MButton type="danger">危险</MButton>
</el-row>
<el-row>
<MButton type="" plain>普通</MButton)
<MButton type="primary" plain>主要</MButton)
<MButton type="success" plain>成功</MButton)
<MButton type="info" plain>信息</MButton>
<MButton type="warning" plain>警告</MButton,
<MButton type="danger"plain>危险</MButton>
</e1-row>
<el-row>
<MButton type="" round>普通</MButton>
<MButton type="primary" round>主要</MButton》
<MButton type="success" round>成功</MButton)
<MButton type="info" round>信息</MButton>
<MButton type="warning" round>警告</MButton:
<MButton type="danger" round>危险</MButton>
</el-row>
<el-row>
<MButton type="" circle icon="fa-trash "></MButton>
<MButton type="primary" circle icon="fa-trash "></MButtonMButton type="success" circle icon="fa-trash "></MButton<MButton type="info" circle icon="fa-trash"></MButton><MButton type="warning" circle icon="fa-trash "></MButton."></MButton>MButton type="danger" circle icon="fa-trash
</el-row>
<MButton type="text">你好</MButton>
>主要</MButton><MButton type="primary"
medium>主要</MButton><MButton type="primary"
MButton type="primary'sma1l>主要</MButton)
mini>主要</MButton><MButton type="primary"
<MButton type="primary":loading="true">加载中</MButton>

 按钮组件源代码:

<template><button :class="[classColorType, classStyleType, classSizeType, classDisable]"><i v-if="loading" class="fa fa-spinner fa-spin"></i><i v-else :class="['fa', icon]"></i><span><slot></slot></span></button>
</template><script>
export default {props: {type: {type: String,default: 'default'},loading: {typeof: Boolean,default: false},icon: {type: String,default: '' // 默认没有图标},mini: {type: Boolean,default: false // 不传则默认为 false},small: {type: Boolean,default: false},medium: {type: Boolean,default: false},plain: {type: Boolean,default: false},round: {type: Boolean,default: false},circle: {type: Boolean,default: false},disabled: {type: Boolean,default: false}},data () {return {myType: this.type}},methods: {changeType () {this.myType = '' // 修改本地数据而不是 prop}},computed: {classDisable () {if (this.disabled) {return 'disabled-button'}return ''},classColorType () {const map = {primary: 'primary-button',success: 'success-button',info: 'info-button',warning: 'warning-button',danger: 'danger-button',text: 'text-button',default: 'color-default-button'}if (this.plain) {return map.default}return map[this.type] || map.default},classStyleType () {if (this.plain) {if (this.type === 'primary') {return 'plain-primary-button'}if (this.type === 'success') {return 'plain-success-button'}if (this.type === 'info') {return 'plain-info-button'}if (this.type === 'warning') {return 'plain-warning-button'}if (this.type === 'danger') {return 'plain-danger-button'}if (this.type === 'default') {return 'color-default-button'}}if (this.round) return 'round-button'if (this.circle) return 'circle-button'return ''},classSizeType () {if (this.medium && !this.circle && this.type !== 'text') return 'medium-button'if (this.small && !this.circle && this.type !== 'text') return 'small-button'if (this.mini && !this.circle && this.type !== 'text') return 'mini-button'return 'size-default-button'}}
}
</script><style scoped lang="less">
button{display: inline-block;border: 1px solid rgb(225, 225, 225);white-space: nowrap;cursor: pointer;text-align: center;box-sizing: border-box;outline: none;font-weight: 500;border-radius: 4px;transition: 0.1s;
}
.fa{display: inline-block;// vertical-align: middle; /* 将图标垂直居中 */margin-bottom: 2px;margin: 0px 2px;
}
.size-default-button{font-size: 14px;height: 40px;line-height: 40px;padding: 1px 20px;
}
.medium-button{font-size: 13px;height: 36px;padding: 0px 18px;line-height: 36px;
}
.small-button{font-size: 12px;height: 32px;padding: 1px 17px;line-height: 32px;
}
.mini-button{font-size: 10px;padding: 0px 16px;height: 28px;
}
.text-button{background-color: #ffffff00;border: none;color: #626262;
}
.text-button:hover{color: #347eff;
}
.color-default-button{background-color: #ffffff;color: #606266;
}
.primary-button{background-color: #5593ff;color: #ffffff;
}
.success-button{background-color: #7fd06d;color: #ffffff;
}
.info-button{background-color: #4d596d;color: #ffffff;
}
.warning-button{background-color: #efb136;color: #ffffff;
}
.danger-button{background-color: #cd5353;color: #ffffff;
}
.primary-button {background-color: #3697ff;color: #ffffff;
}
.success-button {background-color: #28a745;color: #ffffff;
}
.danger-button {background-color: #dc3545;color: #ffffff;
}
/* 不同颜色按钮的 hover 效果 */
.color-default-button:hover {background-color: rgba(202, 228, 255, 0.5); /* 最后一个参数 0.5 表示透明度 */color: #2a7cee;
}
.primary-button:hover {background-color: #0076f5;opacity: 0.5;
}
.info-button:hover {background-color: #5f6861;opacity: 0.5;
}
.warning-button:hover {background-color: #ebc04b;opacity: 0.5;
}
.success-button:hover {background-color: #429d56;opacity: 0.5;
}
.danger-button:hover {background-color: #c82333;opacity: 0.5;
}
.plain-primary-button{color: #0076f5;background-color: rgba(223, 238, 255, 0.5);
}
.plain-success-button{color: #33b847;background-color: rgba(223, 255, 225, 0.5);
}
.plain-info-button{color: #606060;background-color: rgba(228, 228, 228, 0.5);
}
.plain-warning-button{color: #ff9913;background-color: rgba(255, 245, 223, 0.5);
}
.plain-danger-button{color: #f53100;background-color: rgba(255, 223, 223, 0.5);
}
.plain-primary-button:hover{background-color: #5589e3;color: #ffffff;
}
.plain-success-button:hover{background-color: #8adc78;color: #ffffff;
}
.plain-info-button:hover{background-color: #606a7b;color: #ffffff;
}
.plain-warning-button:hover{background-color: hsl(35, 68%, 64%);color: #ffffff;
}
.plain-danger-button:hover{background-color: #e76262;color: #ffffff;
}
.round-button{border-radius: 50% / 100%;
}
.circle-button{width: 40px !important;height: 40px !important;border-radius: 50%;padding-bottom: 1px;align-items: center !important;
}.circle-button i{margin-left: -5px;
}.circle-button span{margin-left: -8px;
}
.disabled-button {cursor: not-allowed !important;opacity: 0.5;pointer-events: none;
}
/* 不同颜色按钮的 active 效果(点击时变淡) */
.color-default-button:active {border: 1px solid rgb(142, 159, 255);color: #659eff;background-color: #c0dbff5c;
}
.primary-button:active {background-color: rgb(39, 117, 195);opacity: 1;
}
.info-button:active {background-color: rgb(65, 62, 62);opacity: 1;
}
.warning-button:active {background-color: rgb(221, 169, 25);opacity: 1;
}
.success-button:active {background-color: rgb(19, 208, 60);opacity: 1;
}
.danger-button:active {background-color: rgb(204, 26, 44);opacity: 1;
}
.plain-primary-button:active {background-color: rgb(52, 106, 198);color: rgb(255, 255, 255);
}
.plain-success-button:active {background-color: rgb(41, 190, 63);color: rgb(255, 255, 255);
}
.plain-info-button:active {background-color: rgb(96, 96, 96);color: rgb(255, 255, 255);
}
.plain-warning-button:active {background-color: rgb(220, 145, 46);color: rgb(255, 255, 255);
}
.plain-danger-button:active {background-color: rgb(215, 89, 89);color: rgb(255, 255, 255);
}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/26252.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

VMWare虚拟机Ubuntu Desktop怎么共享文件夹

1、虚拟机设置 在菜单"管理"里面找到"虚拟机设置"菜单&#xff0c;然后从"硬件"切换到"选项"&#xff0c;点到"共享文件夹"&#xff0c;然后在右侧选中"总是启用"&#xff0c;然后添加一个共享文件夹。 2、在我的…

JAVA安全—手搓内存马

前言 最近在学这个内存马&#xff0c;就做一个记录&#xff0c;说实话这个内存马还是有点难度的。 什么是内存马 首先什么是内存马呢&#xff0c;顾名思义就是把木马打进内存中。传统的webshell一旦把文件删除就断开连接了&#xff0c;而Java内存马则不同&#xff0c;它将恶…

python力扣2:两数相加

给你两个 非空 的链表&#xff0c;表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的&#xff0c;并且每个节点只能存储 一位 数字。 请你将两个数相加&#xff0c;并以相同形式返回一个表示和的链表。 你可以假设除了数字 0 之外&#xff0c;这两个数都不会以 0 开…

CAN硬件协议详解

一、基本理论&#xff1a; 1、CAN的总线结构&#xff1a; CAN总线 网络结构 有 闭环和开环 两种形式&#xff1b;无论实际的网络多复杂&#xff0c;都离不开这两种基本结构。 闭环结构的CAN总线网络&#xff0c;总线的两端各并联一个120Ω的电阻&#xff0c;两…

解决局域网访问Dify却仅显示nginx页面的问题

为什么dify在本机可以正常访问&#xff0c;局域网通过ip访问却只看到欢迎使用nginx的提示&#xff0c;如果访问服务器ip/apps则直接提示404 Not Found。这是怎么回事该如何解决呢&#xff1f;文章中将一步步解决这些问题。 前言 之前在服务器部署了dify&#xff0c;也在服务器…

【前端】——设置菜单的未读状态

用户会接收消息&#xff0c;接收到消息后&#xff0c;需要把待完成的菜单状态改成未读&#xff08;加上小红点提示&#xff09; 例如菜单目录是这样的&#xff0c;需要完成的内容在页面 /test1 里面&#xff0c;但是不光是需要把子菜单 /test1 标记为未完成&#xff0c;其父菜单…

Linux-ftrace-双nop机制的实现

Linux 内核调试工具ftrace 之&#xff08;NOP动态插桩的实现原理&#xff09; ftrace 是 Linux 内核中的一种跟踪工具&#xff0c;主要用于性能分析、调试和内核代码的执行跟踪。它通过在内核代码的关键点插入探针&#xff08;probe&#xff09;来记录函数调用和执行信息。这对…

火山引擎 DeepSeek R1 API 使用小白教程

一、火山引擎 DeepSeek R1 API 申请 首先需要三个要素&#xff1a; 1&#xff09;API Key 2&#xff09;API 地址 3&#xff09;模型ID 1、首先打开火山引擎的 DeepSeek R1 模型页面 地址&#xff1a;账号登录-火山引擎 2、在页面右下角&#xff0c;找到【推理】按钮&#…

在 Element Plus 的 <el-select> 组件中,如果需要将 <el-option> 的默认值设置为 null。 用于枚举传值

文章目录 引言轻松实现 `<el-option>` 的默认值为 `null`I 实现方式监听清空事件 【推荐】使用 v-model 绑定 null添加一个值为 null 的选项处理 null 值的显示引言 背景:接口签名规则要求空串参与,空对象不参与签名计算 // 空字符串“” 参与签名组串,null不参与签…

商业秘密维权有哪些成本开支?

企业商业秘密百问百答之六十三&#xff1a;商业秘密维权费用项目有哪些&#xff1f; 在商业秘密维权过程中&#xff0c;原告可能需要支付多种费用&#xff0c;一般费用项目包括&#xff1a; 1、诉讼费。诉讼费是向法院支付的费用&#xff0c;包括起诉费、案件受理费等。这些费…

StarRocks 在爱奇艺大数据场景的实践

作者&#xff1a;林豪&#xff0c;爱奇艺大数据 OLAP 服务负责人 小编导读&#xff1a; 本文整理自爱奇艺工程师在 StarRocks 年度峰会的分享&#xff0c;介绍了爱奇艺 OLAP 引擎演化及引入 StarRocks 后的效果。 在广告业务中&#xff0c;StarRocks 替换 ImpalaKudu 后&#x…

sql:order by盲注渗透练习

sql-labs靶场46关&#xff1a;order by注入 测试前注意打开小皮面板&#xff0c;打开apache和MySQL服务 http://127.0.0.1:8080/sqli-labs/ 注意端口不要写错 利用orderby注入技术进行排序操作&#xff0c;进而实现报错注入和盲注&#xff0c;最终通过Python脚本自动化提取…

我的世界开发模组的心得体会

最头疼的问题 本人也是小白&#xff0c;也就跟着ai学学怎么开发模组&#xff0c;不会的上网搜搜&#xff0c;但是目前最令我头疼的就是运行rundata和runcilent时的模块冲突&#xff0c;解决办法就是使用以下的build.gradle代码&#xff0c;不要接受人工智能的建议&#xff0c;…

使用pytorch和opencv根据颜色相似性提取图像

需求&#xff1a;将下图中的花朵提取出来。 代码&#xff1a; import cv2 import torch import numpy as np import timedef get_similar_colors(image, color_list, threshold):# 将图像和颜色列表转换为torch张量device torch.device(cuda if torch.cuda.is_available() el…

Redis的优势和特点

什么是redis Remote DIctionary Server(Redis) 是一个由 Salvatore Sanfilippo 写的 key-value 存储系统&#xff0c;是跨平台的非关系型数据库。 Redis 是一个开源的使用 ANSI C 语言编写、遵守 BSD 协议、支持网络、可基于内存、分布式、可选持久性的键值对(Key-Value)存储…

html+js 轮播图

<!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>轮播图示例</title><style>/* 基本样式…

STM32CubeMx DRV8833驱动

一、DRV8833驱动原理 ​ STBY口接单片机的IO口&#xff0c;STBY置0电机全部停止&#xff0c;置1才能工作。STBY置1后通过AIN1、AIN2、BIN1、BIN2 来控制正反转。 AIN1AIN2电机状态00停止1speed反转speed1正转11停止 其中A端&#xff08;AIN1与AIN2&#xff09;只能控制AO1与…

免费轻巧多功能 PDF 处理工具:转换、压缩、提取一应俱全

软件技术 今天要给大家分享一款超实用的 PDF 处理工具&#xff0c;它免费又轻巧&#xff0c;如同随时待命的得力小帮手&#xff0c;功能之强大超乎想象&#xff0c;真的值得大家收藏。 这款工具是绿色版软件&#xff0c;解压后开启&#xff0c;满满的 PDF 处理功能便映入眼帘…

【JAVA SE基础】抽象类和接口

目录 一、前言 二、抽象类 2.1 抽象类的概念 2.2 抽象类语法 2.3 抽象类特性 2.4 抽象类的作用 三、接口 3.1 什么是接口 3.2 语法规则 3.3 接口使用 3.4 接口特性 3.5 实现多接口 3.6 接口间的继承 四、Object类 4.1 获取对象信息&#xff08; toString() &…

C/C++动静态库的制作与原理 -- 静态库,动态库,目标文件,ELF文件,动态链接,静态链接

目录 1. 什么是库 2. 静态库 2.1 静态库的制作 2.2 静态库的使用 3. 动态库 3.1 动态库的制作 3.2 动态库的使用 4. 目标文件 5. ELF文件 6. ELF从形成到加载轮廓 6.1 ELF形成可执行 7.2 ELF可执行文件加载 7. 理解链接和加载 7.1 静态链接 7.2 ELF加载与进程地…