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

【vue.js】在网页中实现一个金属抛光质感的按钮

文章目录

  • 前言
  • 效果
    • 电脑效果
    • 手机效果
  • 说明
  • 完整代码
    • index.html

前言

诶?这有一个按钮(~ ̄▽ ̄)~,这是一个在html中实现的具有金属质感并且能镜面反射的按钮~

效果

在这里插入图片描述

电脑效果

在这里插入图片描述

手机效果

在这里插入图片描述

说明

主要思路是使用 navigator.mediaDevices.getUserMedia()调用设备摄像头来实现镜面反射,css部分用到了filter属性,后期可以根据需要调整它的属性值,做出更多反射效果。有了思路,实现起来还是比较简单的。

需要注意的是window.navigator.mediaDevices.getUserMedia()只能在localhosthttps下才能使用,否则会报错哦。

完整代码

index.html

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"><script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script><style>body {background-color: rgb(86, 86, 86);}:root {--transition: 0.1s;--border-radius: 56px;}.button-wrap {margin: calc(30vh - 50px) auto 0;width: 300px;height: 100px;position: relative;transition: transform var(--transition), box-shadow var(--transition);}.button-wrap.pressed {transform: translateZ(0) scale(0.98);}.button {width: 100%;height: 100%;overflow: hidden;border-radius: var(--border-radius);box-shadow:0px 0px 10px rgba(0, 0, 0, 0.6),0px 0px 20px rgba(0, 0, 0, 0.4),0px 0px 40px rgba(0, 0, 0, 0.2),inset 0 2px 2px rgba(255, 255, 255, 0.8),inset 0 -2px 2px rgba(255, 255, 255, 0.8);transform: translateZ(0);cursor: pointer;}.button.pressed {box-shadow:0px 0px 5px rgba(0, 0, 0, 0.6),0px 0px 10px rgba(0, 0, 0, 0.4),0px 0px 20px rgba(0, 0, 0, 0.2),inset 0 2px 2px rgba(255, 255, 255, 0.8),inset 0 -2px 2px rgba(255, 255, 255, 0.8);}.text {position: absolute;left: 50%;top: 50%;transform: translate(-50%, -50%);pointer-events: none;color: rgba(0, 0, 0, 0.9);font-size: 48px;font-weight: bold;text-shadow:0px 2px 1px rgba(255, 255, 255, 0.3),0px -2px 1px rgba(255, 255, 255, 0.3);}.text::selection {background-color: transparent;}.button .button-reflection {width: 100%;height: 100%;transform: scaleX(-1);object-fit: cover;opacity: 0.7;filter: blur(2px) saturate(0.6) brightness(1.1);object-position: 0 -100px;}</style>
</head><body><div id="app"><div v-show="cameraOpened" :class="`button-wrap ${buttonPressed ? 'pressed' : ''}`"><div :class="`button ${buttonPressed ? 'pressed' : ''}`" @mousedown="setButtonPressed(true)"@mouseup="setButtonPressed(false)" @touchstart="setButtonPressed(true)" @touchend="setButtonPressed(false)"><video class="button-reflection" ref="reflectionRef" /></div><div class="text">Button</div></div></div><script>new Vue({el: '#app',data: {cameraOpened: false,buttonPressed: false},mounted() {const _this = thisnavigator.mediaDevices.getUserMedia({video: true,audio: false}).then((stream) => {const video = this.$refs.reflectionRefvideo.srcObject = stream;video.onloadedmetadata = () => {_this.cameraOpened = truevideo.play()}})},methods: {setButtonPressed(val) {this.buttonPressed = val}}})</script>
</body></html>
http://www.lryc.cn/news/40821.html

相关文章:

  • android实现评论区功能
  • Java每日一练(20230319)
  • Redis缓存双写一致性
  • 【2023-Pytorch-检测教程】手把手教你使用YOLOV5做交通标志检测
  • Java中的二叉树
  • 基于 gma 绘制古代洛阳 5 大都城遗址空间分布地图
  • 分析 Spring 的依赖注入模式
  • IntelliJ IDEA创建Servlet
  • Spring Boot如何让自己的bean优先加载
  • LeetCode分类刷题----动态规划
  • 今年好像没有金三银四了?
  • 【C++】入门知识之 函数重载
  • 文心一言发布,你怎么看?chatGPT
  • 字符函数和字符串函数【上篇】
  • list的模拟实现(模仿STL)
  • 05-STM32F1 - 串行通信SPI
  • 【Pytorch】Tensor的分块、变形、排序、极值与in-place操作
  • 数组栈的实现
  • *p++,*(p++),*++p,(*p)++区别?
  • 又一个线上偶发问题-系统短暂无法获取到Redis连接
  • [ 系统安全篇 ] 拉黑IP - 火绒安全软件设置IP黑名单 windows使用系统防火墙功能设置IP黑名单
  • MongoDB【部署 01】mongodb最新版本6.0.5安装部署配置使用及mongodb-shell1.8.0安装使用(云盘分享安装文件)
  • 算法竞赛必考算法——动态规划(01背包和完全背包)
  • 基于深度学习的农作物叶片病害检测系统(UI界面+YOLOv5+训练数据集)
  • QT入门Item Views之QListView
  • GEE:计算1990-2021年的指数最大值和最小值,并根据最大最小值对每一副影像归一化
  • LeetCode KMP 算法
  • 全面剖析OpenAI发布的GPT-4比其他GPT模型强在哪里
  • leetcode——26. 删除有序数组中的重复项
  • 基于springboot垃圾分类网站设计实现【毕业论文、源码】