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

网站五角星评分组件

网站五角星评分组件

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><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;}.rating-container {text-align: center;}.stars {font-size: 2rem;color: #ddd; /* 默认灰色 */cursor: pointer;}.star {transition: color 0.2s ease;}.star:hover,.star.active {color: #ffcc00; /* 悬停或激活时变为黄色 */}.score-display {margin-top: 10px;font-size: 1.2rem;color: #333;}</style>
</head>
<body><div class="rating-container"><div class="stars" id="stars"><!-- 初始为空心星星 --></div><div class="score-display" id="score">请选择评分</div></div><script>const starsContainer = document.getElementById('stars');const scoreDisplay = document.getElementById('score');const maxStars = 10;// 初始化星星状态
        let currentRating = 0;// 添加点击事件监听器
        starsContainer.addEventListener('click', (e) => {if (e.target.classList.contains('star')) {const index = parseInt(e.target.getAttribute('data-index'));updateRating(index + 1);}});// 添加鼠标悬停效果
        starsContainer.addEventListener('mouseover', (e) => {if (e.target.classList.contains('star')) {const index = parseInt(e.target.getAttribute('data-index'));highlightStars(index + 1);}});// 移除悬停效果
        starsContainer.addEventListener('mouseout', () => {highlightStars(currentRating);});// 更新评分function updateRating(rating) {currentRating = rating;highlightStars(rating);scoreDisplay.textContent = `当前评分:${rating} 星`;}// 高亮星星(实心黄色)function highlightStars(count) {const stars = starsContainer.querySelectorAll('.star');stars.forEach((star, index) => {if (index < count) {star.textContent = ''; // 实心星星
                    star.classList.add('active');} else {star.textContent = ''; // 空心星星
                    star.classList.remove('active');}});}// 初始化星星元素(默认为空心)function initStars() {const starsHTML = [];for (let i = 0; i < maxStars; i++) {starsHTML.push(`<span class="star" data-index="${i}"></span>`); // 默认空心星星}starsContainer.innerHTML = starsHTML.join('');}// 页面加载完成后初始化
        window.onload = () => {initStars();};</script>
</body>
</html>

 

http://www.jsqmd.com/news/394644/

相关文章:

  • State Design Matters How Representations Shape Dynamic Reasoning in Large Language Models
  • A Systematic Evaluation of Sample-Level Tokenization Strategies for MEG Foundation Models
  • 题解:洛谷 P2047 [NOI2007] 社交网络
  • 题解:洛谷 P5960 【模板】差分约束
  • 【MyBatis Exception】省略动态SQL中的‘‘,会造成Runtime Exception
  • 信号完整性测试中的skew
  • 启动流程全解密:从MaskRom到Loader再到Linux内核的破晓之路
  • 【医疗影像检测】VFNet模型在医疗器械目标检测中的应用与优化 - 详解
  • 题解:洛谷 P2419 [USACO08JAN] Cow Contest S
  • 深山藏匠心,粉润传千年——多跃有机野生葛根粉,用初心做一碗真葛根 - 品牌企业推荐师(官方)
  • 用数据说话 AI论文平台 千笔ai写作 VS 云笔AI 更贴合专科生需求
  • 2026 年 1-2 月 GEO 服务商 TOP10 选型速查表 - 品牌企业推荐师(官方)
  • 导师又让重写?一键生成论文工具 千笔ai写作 VS speedai,专科生专属神器!
  • 靠谱的数控开料机生产基地 - 品牌企业推荐师(官方)
  • 庐州匠心奢改图鉴:合肥四大高端改衣机构解锁奢侈品焕新密码 - 品牌企业推荐师(官方)
  • 官网-宿迁市城乡居民基本养老保险丧葬补助金制度
  • 题解:洛谷 P1073 [NOIP 2009 提高组] 最优贸易
  • 题解:洛谷 P1037 [NOIP 2002 普及组] 产生数
  • 给游戏开发者的【海外 Steam 愿望单获取方法】
  • 2026污水池清洗企业排名,口碑佳选在这里!污水池清洗企业哪家好技术引领与行业解决方案解析 - 品牌推荐师
  • 掌握这些,2026选国内热门S系列减速机工厂不踩坑,硬齿面斜齿轮减速机/提升机减速机,S系列减速机实力厂家哪家强 - 品牌推荐师
  • C#异步和并发在IO密集场景的典型应用 async/await
  • 题解:洛谷 P3385 【模板】负环
  • 2026年大件物流哪家强?口碑厂家精选指南,大件运输/大件物流,大件物流服务商口碑排行 - 品牌推荐师
  • 看完马斯克的“编程末日”预言,我反而松了一口气
  • 题解:洛谷 P4779 【模板】单源最短路径(标准版)
  • 矩阵乘法与同维空间互相转换(以二维为例)
  • 世毫九理论体系·正式总目录
  • 题解:洛谷 P1600 [NOIP 2016 提高组] 天天爱跑步
  • 美团礼品卡回收实用指南解决闲置困扰 - 京顺回收