下面是最终效果,手指移出指定区域就改为取消状态,松开手指就取消,手指没有移出指定区域,状态为录音中,松开手指为结束录音状态
下面是代码
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>语音交互样式</title> <style> body { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f5f5f5; } .voice-container { position: relative; width: 200px; height: 200px; } /* 语音交互按钮 */ .voice-btn { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); width: 80px; height: 80px; background-color: #4CAF50; border-radius: 50%; display: flex; justify-content: center; align-items: center; color: white; font-size: 20px; cursor: pointer; transition: background-color 0.3s; } .voice-btn:active { background-color: #388E3C; } /* 正在语音识别的状态 */ .voice-recognizing { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; height: 100px; background-color: rgba(0, 0, 0, 0.2); border-radius: 20px 20px 0 0; display: flex; justify-content: center; align-items: center; color: white; font-size: 16px; display: none; /* 默认隐藏 */ transition: background-color 0.3s; } /* 预取消状态:当手指移出语音识别区域时,改变样式 */ .voice-recognizing.canceling { background-color: rgba(255, 0, 0, 0.5); /* 改为红色表示预取消 */ } /* 取消区域:顶部区域用于取消语音识别 */ .cancel-area { position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 100%; height: 30px; background-color: rgba(255, 0, 0, 0.8); /* 红色背景 */ color: white; text-align: center; line-height: 30px; font-size: 14px; display: none; /* 默认隐藏 */ cursor: pointer; z-index: 1; } /* 取消区域显示 */ .cancel-area.show { display: block; } /* 取消区域 hover 样式 */ .cancel-area:hover { background-color: rgba(255, 0, 0, 1); } </style> </head> <body> <div class="voice-container"> <!-- 语音交互按钮 --> <div class="voice-btn" id="voiceBtn"> 标签:识别,false,语音,样式,取消,voiceRecognizing,按住,移动,color From: https://www.cnblogs.com/unique-yaobo/p/18547615