js+css实现一个markdown文本生成不同风格模板的文字卡片图片效果代码
代码语言:html
所属分类:布局界面
代码描述:js+css实现一个markdown文本生成不同风格模板的文字卡片图片效果代码,可调整颜色及卡片风格样式,内置了20个模板。
代码标签: js css markdown 文本 生成 不同 风格 模板 颜色 文字 卡片 图片
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>动态文字卡片生成器</title>
<!-- 引入 Font Awesome 图标 -->
<link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/all.6.4.0.css">
<!-- 引入 Marked.js 用于 Markdown 解析 -->
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/marked.min.js"></script>
<!-- 引入 html2canvas 用于生成图片 -->
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/html2canvas.1.4.1.js"></script>
<!-- 引入 Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&family=Indie+Flower&family=Orbitron:wght@400;700&family=Lora:ital@0;1&family=Playfair+Display:wght@400;700&family=Merriweather:wght@400;700&family=Montserrat:wght@400;700&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
}
body {
background-color: #f5f7fa;
color: #333;
line-height: 1.6;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 30px;
}
@media (max-width: 768px) {
.container {
grid-template-columns: 1fr;
}
}
.header {
grid-column: 1 / -1;
text-align: center;
margin-bottom: 30px;
}
.header h1 {
font-size: 2.5rem;
font-weight: 700;
color: #2c3e50;
margin-bottom: 15px;
background: linear-gradient(45deg, #3498db, #8e44ad);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
letter-spacing: 1px;
}
.header p {
font-size: 1.1rem;
color: #7f8c8d;
max-width: 700px;
margin: 0 auto;
}
.editor-section {
background-color: white;
border-radius: 16px;
padding: 25px;
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.07);
}
.section-title {
display: flex;
align-items: center;
margin-bottom: 20px;
font-size: 1.25rem;
font-weight: 600;
color: #2c3e50;
}
.section-title i {
margin-right: 12px;
color: #3498db;
font-size: 1.4rem;
}
textarea {
width: 100%;
height: 300px;
padding: 15px;
border: 1px solid #e0e6ed;
border-radius: 8px;
font-size: 1rem;
resize: vertical;
margin-bottom: 20px;
font-family: 'Consolas', 'Courier New', monospace;
}
textarea:focus {
outline: none;
border-color: #3498db;
box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}
.template-selector {
margin-bottom: 20px;
}
.template-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 15px;
margin-top: 15px;
max-height: 400px;
overflow-y: auto;
padding-right: 10px;
}
@media (max-width: 768px) {
.template-grid {
grid-template-columns: repeat(2, 1fr);
}
}
.template-option {
border: 2px solid #e0e6ed;
border-radius: 8px;
padding: 15px;
text-align: center;
cursor: pointer;
transition: all 0.3s ease;
}
.template-option:hover {
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}
.template-option.active {
border-color: #3498db;
background-color: rgba(52, 152, 219, 0.05);
}
.template-preview {
width: 100%;
height: 120px;
border-radius: 4px;
margin-bottom: 10px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-weight: bold;
color: inherit;
transition: all 0.3s ease;
position: relative;
overflow: hidden;
}
.template-preview:hover {
transform: scale(1.05);
}
.template-option h4 {
font-size: 1rem;
color: #2c3e50;
margin-bottom: 5px;
}
.template-option p {
font-size: 0.8rem;
color: #7f8c8d;
margin: 0;
}
.color-options {
display: flex;
gap: 10px;
margin-top: 15px;
flex-wrap: wrap;
}
.color-option {
width: 30px;
height: 30px;
border-radius: 50%;
cursor: pointer;
transition: transform 0.2s ease;
border: 2px solid #fff;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.color-option:hover {
transform: scale(1.1);
}
.color-option.active {
border: 2px solid #333;
}
.preview-section {
background-color: white;
border-radius: 16px;
padding: 25px;
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.07);
display: flex;
flex-direction: column;
}
.preview-container {
flex-grow: 1;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
overflow: hidden;
}
.card-preview {
width: 100%;
max-width: 500px;
min-height: 300px;
overflow: hidden;
transition: all 0.3s ease;
position: relative;
}
.card-preview::before {
/* 将由JavaScript动态设置 */
}
.card-preview .markdown-content {
height: 100%;
}
/* 为不同模板的标题添加动画效果 */
.card-preview h1, .card-preview h2, .card-preview h3 {
position: relative;
overflow: hidden;
}
/* 为引用块添加更好的样式支持 */
.card-preview blockquote {
position: relative;
overflow: hidden;
}
.markdown-content {
line-height: 1.8;
}
.markdown-content h1 {
font-size: 2rem;
margin-bottom: 15px;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
padding-bottom: 10px;
}
.markdown-content h2 {
font-size: 1.5rem;
margin-bottom: 12px;
margin-top: 25px;
}
.markdown-content h3 {
f.........完整代码请登录后点击上方下载按钮下载查看
网友评论0