claude-sonnet-4-20250514· Anthropic LMArena Human Preference 140K
帮我设计一个电商图标的web程序, 内置很多模板,html
- User
帮我设计一个电商图标的web程序, 内置很多模板,html
- Assistant
我来帮你设计一个电商图标生成器的web程序。这个程序将包含多个预设模板,用户可以选择并自定义图标。
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>电商图标生成器</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Arial', sans-serif; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); min-height: 100vh; padding: 20px; } .container { max-width: 1200px; margin: 0 auto; background: white; border-radius: 15px; box-shadow: 0 20px 40px rgba(0,0,0,0.1); overflow: hidden; } .header { background: linear-gradient(45deg, #ff6b6b, #ee5a24); color: white; padding: 30px; text-align: center; } .header h1 { font-size: 2.5em; margin-bottom: 10px; } .main-content { display: flex; min-height: 600px; } .sidebar { width: 300px; background: #f8f9fa; padding: 20px; border-right: 1px solid #e9ecef; } .template-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin-bottom: 30px; } .template-item { width: 100px; height: 100px; border: 2px solid #ddd; border-radius: 10px; cursor: pointer; transition: all 0.3s ease; display: flex; align-items: center; justify-content: center; font-size: 2em; background: white; } .template-item:hover { border-color: #007bff; transform: translateY(-2px); box-shadow: 0 5px 15px rgba(0,123,255,0.3); } .template-item.active { border-color: #007bff; background: #e3f2fd; } .controls { margin-top: 20px; } .control-group { margin-bottom: 20px; } .control-group label { display: block; margin-bottom: 5px; font-weight: bold; color: #333; } .control-group input, .control-group select { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 5px; font-size: 14px; } .color-input { height: 40px; border: none; border-radius: 5px; cursor: pointer; } .preview-area { flex: 1; padding: 40px; display: flex; flex-direction: column; align-items: center; justify-content: center; } .icon-preview { width: 200px; height: 200px; border: 2px dashed #ddd; border-radius: 15px; display: flex; align-items: center; justify-content: center; font-size: 4em; margin-bottom: 30px; transition: all 0.3s ease; position: relative; overflow: hidden; } .download-btn { background: linear-gradient(45deg, #28a745, #20c997); color: white; border: none; padding: 15px 30px; border-radius: 25px; font-size: 16px; cursor: pointer; transition: all 0.3s ease; box-shadow: 0 5px 15px rgba(40,167,69,0.3); } .download-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(40,167,69,0.4); } .template-name { text-align: center; font-size: 12px; margin-top: 5px; color: #666; } /* 图标样式 */ .shopping-cart { color: #ff6b6b; } .heart { color: #e74c3c; } .star { color: #f39c12; } .bag { color: #9b59b6; } .gift { color: #e67e22; } .diamond { color: #3498db; } .crown { color: #f1c40f; } .tag { color: #2ecc71; } /* 响应式设计 */ @media (max-width: 768px) { .main-content { flex-direction: column; } .sidebar { width: 100%; } .template-grid { grid-template-columns: repeat(4, 1fr); } .template-item { width: 80px; height: 80px; font-size: 1.5em; } } </style> </head> <body> <div class="container"> <div class="header"> <h1>🛍️ 电商图标生成器</h1> <p>选择模板,自定义样式,一键生成专业电商图标</p> </div> <div class="main-content"> <div class="sidebar"> <h3>选择模板</h3> <div class="template-grid"> <div class="template-item shopping-cart active" data-icon="🛒" data-name="购物车"> 🛒 <div class="template-name">购物车</div> </div> <div class="template-item heart" data-icon="❤️" data-name="收藏"> ❤️ <div class="template-name">收藏</div> </div> <div class="template-item star" data-icon="⭐" data-name="评价"> ⭐ <div class="template-name">评价</div> </div> <div class="template-item bag" data-icon="👜" data-name="购物袋"> 👜 <div class="template-name">购物袋</div> </div> <div class="template-item gift" data-icon="🎁" data-name="礼品"> 🎁 <div class="template-name">礼品</div> </div> <div class="template-item diamond" data-icon="💎" data-name="钻石"> 💎 <div class="template-name">钻石</div> </div> <div class="template-item crown" data-icon="👑" data-name="皇冠"> 👑 <div class="template-name">皇冠</div> </div> <div class="template-item tag" data-icon="🏷️" data-name="标签"> 🏷️ <div class="template-name">标签</div> </div> </div> <div class="controls"> <div class="control-group"> <label>背景颜色</label> <input type="color" id="bgColor" class="color-input" value="#ffffff"> </div> <div class="control-group"> <label>图标大小</label> <input type="range" id="iconSize" min="50" max="150" value="80"> </div> <div class="control-group"> <label>边框样式</label> <select id="borderStyle"> <option value="none">无边框</option> <option value="solid">实线</option> <option value="dashed">虚线</option> <option value="dotted">点线</option> </select> </div> <div class="control-group"> <label>边框颜色</label> <input type="color" id="borderColor" class="color-input" value="#007bff"> </div> <div class="control-group"> <label>圆角大小</label> <input type="range" id="borderRadius" min="0" max="50" value="15"> </div> <div class="control-group"> <label>阴影效果</label> <select id="shadowEffect"> <option value="none">无阴影</option> <option value="light">轻微阴影</option> <option value="medium">中等阴影</option> <option value="heavy">重阴影</option> </select> </div> </div> </div> <div class="preview-area"> <div class="icon-preview" id="iconPreview"> 🛒 </div> <button class="download-btn" onclick="downloadIcon()"> 📥 下载图标 </button> </div> </div> </div> <script> let currentIcon = '🛒'; // 模板选择 document.querySelectorAll('.template-item').forEach(item => { item.addEventListener('click', function() { document.querySelectorAll('.template-item').forEach(i => i.classList.remove('active')); this.classList.add('active'); currentIcon = this.dataset.icon; updatePreview(); }); }); // 控制面板事件监听 document.getElementById('bgColor').addEventListener('input', updatePreview); document.getElementById('iconSize').addEventListener('input', updatePreview); document.getElementById('borderStyle').addEventListener('change', updatePreview); document.getElementById('borderColor').addEventListener('input', updatePreview); document.getElementById('borderRadius').addEventListener('input', updatePreview); document.getElementById('shadowEffect').addEventListener('change', updatePreview); function updatePreview() { const preview = document.getElementById('iconPreview'); const bgColor = document.getElementById('bgColor').value; const iconSize = document.getElementById('iconSize').value; const borderStyle = document.getElementById('borderStyle').value; const borderColor = document.getElementById('borderColor').value; const borderRadius = document.getElementById('borderRadius').value; const shadowEffect = document.getElementById('shadowEffect').value; preview.innerHTML = currentIcon; preview.style.backgroundColor = bgColor; preview.style.fontSize = iconSize + 'px'; preview.style.borderRadius = borderRadius + 'px'; // 边框样式 if (borderStyle === 'none') { preview.style.border = 'none'; } else { preview.style.border = `3px ${borderStyle} ${borderColor}`; } // 阴影效果 switch(shadowEffect) { case 'none': preview.style.boxShadow = 'none'; break; case 'light': preview.style.boxShadow = '0 2px 8px rgba(0,0,0,0.1)'; break; case 'medium': preview.style.boxShadow = '0 5px 15px rgba(0,0,0,0.2)'; break; case 'heavy': preview.style.boxShadow = '0 10px 30px rgba(0,0,0,0.3)'; break; } } function downloadIcon() { const preview = document.getElementById('iconPreview'); const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); canvas.width = 200; canvas.height = 200; // 获取当前样式 const bgColor = document.getElementById('bgColor').value; const borderRadius = document.getElementById('borderRadius').value; // 绘制背景 ctx.fillStyle = bgColor; if (borderRadius > 0) { roundRect(ctx, 0, 0, 200, 200, borderRadius); ctx.fill(); } else { ctx.fillRect(0, 0, 200, 200); } // 绘制图标 (这里简化处理,实际项目中可能需要更复杂的图标渲染) ctx.font = document.getElementById('iconSize').value + 'px Arial'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillStyle = '#333'; ctx.fillText(currentIcon, 100, 100); // 下载 const link = document.createElement('a'); link.download = 'ecommerce-icon.png'; link.href = canvas.toDataURL(); link.click(); } function roundRect(ctx, x, y, width, height, radius) { ctx.beginPath(); ctx.moveTo(x + radius, y); ctx.lineTo(x + width - radius, y); ctx.quadraticCurveTo(x + width, y, x + width, y + radius); ctx.lineTo(x + width, y + height - radius); ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height); ctx.lineTo(x + radius, y + height); ctx.quadraticCurveTo(x, y + height, x, y + height - radius); ctx.lineTo(x, y + radius); ctx.quadraticCurveTo(x, y, x + radius, y); ctx.closePath(); } // 初始化预览 updatePreview(); </script> </body> </html>这个电商图标生成器包含以下功能:
主要特性:
- 8个预设电商图标模板(购物车、收藏、评价、购物袋等)
- 实时预览功能
- 多种自定义选项:背景颜色、图标大小、边框样式、圆角、阴影效果
- 响应式设计,支持移动端
- 一键下载生成的图标
使用方法:
- 选择左侧的图标模板
- 调整右侧