<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SVG评价图标复选框动画</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #f5f5f5;
margin: 0;
padding: 20px;
}
.rating-container {
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.rating-title {
font-size: 18px;
color: #333;
margin-bottom: 10px;
}
.rating-options {
display: flex;
gap: 15px;
}
.rating-option {
position: relative;
cursor: pointer;
}
.rating-input {
position: absolute;
opacity: 0;
width: 0;
height: 0;
}
.rating-icon {
width: 50px;
height: 50px;
transition: all 0.3s ease;
fill: #ddd;
}
.rating-input:checked + .rating-icon {
fill: #4CAF50;
transform: scale(1.1);
}
.rating-input:not(:checked) + .rating-icon:hover {
fill: #bbb;
transform: scale(1.05);
}
.rating-labels {
display: flex;
justify-content: space-between;
width: 100%;
margin-top: 10px;
font-size: 12px;
color: #666;
}
.submit-btn {
margin-top: 20px;
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
.submit-btn:hover {
background-color: #45a049;
}
.checkmark {
stroke: white;
stroke-width: 2;
stroke-dasharray: 30;
stroke-dashoffset: 30;
transition: stroke-dashoffset 0.3s ease-out;
}
.rating-input:checked ~ .checkmark {
stroke-dashoffset: 0;
}
</style>
</head>
<body>
<div class="rating-container">
<div class="rating-title">请评价我们的服务</div>
<div class="rating-options">
<!-- 差评 -->
<label class="rating-option">
<input type="checkbox" class="rating-input" name="rating" value="1">
<svg class="rating-icon" viewBox="0 0 24 24">
<path d="M12,2C6.47,2,2,6.47,2,12s4.47,10,10,10s10-4.47,10-10S17.53,2,12,2z M12,20c-4.41,0-8-3.59-8-8s3.59-8,8-8s8,3.59,8,8 S16.41,20,12,20z"/>
<path d="M16,16H8v-2h8V16z"/>
<path d="M16,12H8v-2h8V12z"/>
<path class="checkmark" d="M8,8l4,4l4-4"/>
</svg>
</label>
<!-- 一般 -->
<label class="rating-option">
<input type="checkbox" class="rating-input" name="rating" value="2">
<svg class="rating-icon" viewBox="0 0 24 24">
<path d="M12,2C6.47,2,2,6.47,2,12s4.47,10,10,10s10-4.47,10-10S17.53,2,12,2z M12,20c-4.41,0-8-3.59-8-8s3.59-8,8-8s8,3.59,8,8 S16.41,20,12,20z"/>
<path d="M16,16H8v-2h8V16z"/>
<path class="checkmark" d="M8,12l4,4l4-4"/>
</svg>
</label>
<!-- 满意 -->
<label class="rating-option">
<input type="checkbox" class="rating-input" name="rating" value="3">
<svg class="rating-icon" viewBox="0 0 24 24">
<path d="M12,2C6.47,2,2,6.47,2,12s4.47,10,10,10s10-4.47,10-10S17.53,2,12,2z M12,20c-4.41,0-8-3.59-8-8s3.59-8,8-8s8,3.59,8,8 S16.41,20,12,20z"/>
<path d="M7,10h10v2H7V10z"/>
<path class="checkmark" d="M8,12l4,4l4-4"/>
</svg>
</label>
<!-- 很好 -->
<label class="rating-option">
<input type="checkbox" class="rating-input" name="rating" value="4">
<svg class="rating-icon" viewBox="0 0 24 24">
<path d="M12,2C6.47,2,2,6.47,2,12s4.47,10,10,10s10-4.47,10-10S17.53,2,12,2z M12,20c-4.41,0-8-3.59-8-8s3.59-8,8-8s8,3.59,8,8 S16.41,20,12,20z"/>
<path d="M7,10h10v2H7V10z"/>
<path d="M10,15h4v2h-4V15z"/>
<path class="checkmark" d="M8,12l4,4l4-4"/>
</svg>
</label>
<!-- 非常好 -->
<label class="rating-option">
<input type="checkbox" class="rating-input" name="rating" value="5">
<svg class="rating-icon" viewBox="0 0 24 24">
<path d="M12,2C6.47,2,2,6.47,2,12s4.47,10,10,10s10-4.47,10-10S17.53,2,12,2z M12,20c-4.41,0-8-3.59-8-8s3.59-8,8-8s8,3.59,8,8 S16.41,20,12,20z"/>
<path d="M7,10h10v2H7V10z"/>
<path d="M10,14h4v2h-4V14z"/>
<path d="M10,7h4v2h-4V7z"/>
<path class="checkmark" d="M8,12l4,4l4-4"/>
</svg>
</label>
</div>
<div class="rating-labels">
<span>差评</span>
<span>一般</span>
<span>满意</span>
<span>很好</span>
<span>非常好</span>
</div>
<button class="submit-btn">提交评价</button>
</div>
<script>
// 确保一次只能选择一个评价
document.querySelectorAll('.rating-input').forEach(input => {
input.addEventListener('change', function() {
if(this.checked) {
document.querySelectorAll('.rating-input').forEach(otherInput => {
if(otherInput !== this) {
otherInput.checked = false;
}
});
}
});
});
// 提交按钮点击事件
document.querySelector('.submit-btn').addEventListener('click', function() {
const selectedRating = document.querySelector('.rating-input:checked');
if(selectedRating) {
alert(`感谢您的评价!您选择了 ${selectedRating.value} 星评价。`);
} else {
alert('请选择一个评价等级!');
}
});
</script>
</body>
</html>
SVG简约评价图标复选框动画特效
于 2025-05-24 16:01:07 首次发布
256

被折叠的 条评论
为什么被折叠?



