自定义样式
如果有开发能力的伙伴,觉得默认的提交框太7+1了,可以自己魔改样式,需要注意的是,使用自定义样式会覆盖掉默认的样式,如果你只想在默认样式的基础上微调,你可以先把默认样式代码写上,然后再添加自己的个性化样式代码
如果使用自定义模板,一定要保证form中的输入框id与默认模板代码中的一致,参考下方默认提交框代码片段
${siteInfo}
:站点信息${redirectPage}
:跳转地址${verifyCodeHtmlTpl}
:验证码获取方式代码,图形验证码或者是邮箱验证码,动态切换- 图形:
<img id="verifyCodeImg" class="linksSubmit-verifyCodeImg" src="/apis/linksSubmit.muyin.site/v1alpha1/captcha" title="点击刷新验证码" alt="验证码"> <a class="linksSubmit-verifyCodeImg-refresh" href="javascript:void(0);" onclick="refreshVerifyCode()">看不清?换一张</a>
- 邮箱:
<button id="verifyCodeBtn" class="linksSubmit-verifyCodeBtn" type="button" onclick="sendVerifyCode(this)">获取验证码</button>
- 图形:
linksSubmitToast(msg, duration)
:气泡提示框linksSubmitAction(redirectPage)
:表单提交copyBlogInfo()
:复制站点信息sendVerifyCode(e)
:发送邮箱验证码refreshVerifyCode()
:刷新图形验证码openOverlay()
:打开弹窗遮罩层closeOverlay()
:关闭弹窗遮罩层
<form
id="linksSubmit-form"
class="linksSubmit-form"
onclick="event.stopPropagation()"
>
<div class="linksSubmit-title-container">
<div class="linksSubmit-left-title">
<div class="linksSubmit-title">友链提交</div>
<div class="linksSubmit-subtitle">请认真填写以下信息,谢谢!</div>
</div>
<div class="linksSubmit-right-title">
<div class="linksSubmit-card">
<div class="linksSubmit-card-align">
<span class="linksSubmit-card-red"></span>
<span class="linksSubmit-card-yellow"></span>
<span class="linksSubmit-card-green"></span>
</div>
<h1 class="linksSubmit-card-title">博客信息</h1>
<div class="linksSubmit-card-content">${siteInfo}</div>
<button
class="linksSubmit-card-btn"
type="button"
onclick="copyBlogInfo(this)"
>
复制信息
</button>
</div>
</div>
</div>
<div class="linksSubmit-input-container">
<div class="linksSubmit-input-option">
<input
placeholder=""
type="text"
class="linksSubmit-input"
id="displayName"
name="displayName"
required
onblur="checkInput(this)"
/>
<div class="linksSubmit-cut"></div>
<label class="linksSubmit-iLabel" for="displayName">网站名称</label>
</div>
<div class="linksSubmit-input-option">
<input
placeholder=""
type="url"
class="linksSubmit-input"
id="url"
name="url"
required
onblur="checkInput(this)"
/>
<div class="linksSubmit-cut"></div>
<label class="linksSubmit-iLabel" for="url">网站地址</label>
</div>
<div class="linksSubmit-input-option">
<input
placeholder=""
type="url"
class="linksSubmit-input"
id="logo"
name="logo"
onblur="checkInput(this)"
/>
<div class="linksSubmit-cut"></div>
<label class="linksSubmit-iLabel" for="logo">网站图标</label>
</div>
<div class="linksSubmit-input-option">
<select
class="linksSubmit-input"
id="groupName"
name="groupName"
onblur="checkInput(this)"
></select>
<div class="linksSubmit-cut"></div>
<label class="linksSubmit-iLabel" for="groupName">友链分组</label>
</div>
<div class="linksSubmit-input-option">
<input
placeholder=""
type="url"
class="linksSubmit-input"
id="linkPageUrl"
name="linkPageUrl"
onblur="checkInput(this)"
/>
<div class="linksSubmit-cut"></div>
<label class="linksSubmit-iLabel" for="linkPageUrl">友链页面</label>
<span class="linksSubmit-iLabel-tip"
>(贵站展示本站链接的页面地址,一般是友链页面,填写后将自动验证友链关系有效性)</span
>
</div>
<div class="linksSubmit-input-option">
<input
placeholder=""
type="url"
class="linksSubmit-input"
id="rssUrl"
name="rssUrl"
onblur="checkInput(this)"
/>
<div class="linksSubmit-cut"></div>
<label class="linksSubmit-iLabel" for="rssUrl">RSS 地址</label>
<span class="linksSubmit-iLabel-tip">(用于抓取文章)</span>
</div>
<div class="linksSubmit-input-option description">
<textarea
placeholder=""
class="linksSubmit-input"
id="description"
name="description"
onblur="checkInput(this)"
></textarea>
<div class="linksSubmit-cut"></div>
<label class="linksSubmit-iLabel" for="description">网站描述</label>
</div>
<div class="linksSubmit-input-option">
<input
placeholder=""
type="email"
class="linksSubmit-input"
id="email"
name="email"
required
onblur="checkInput(this)"
/>
<div class="linksSubmit-cut"></div>
<label class="linksSubmit-iLabel" for="email">邮箱地址</label>
<span class="linksSubmit-iLabel-tip">(用于接收通知)</span>
</div>
<div class="linksSubmit-input-option">
<input
placeholder=""
type="text"
class="linksSubmit-input linksSubmit-verifyCode"
id="verifyCode"
name="verifyCode"
required
onblur="checkInput(this)"
/>
<div class="linksSubmit-verifyCodeDiv">${verifyCodeHtmlTpl}</div>
<div class="linksSubmit-cut linksSubmit-cut-short"></div>
<label class="linksSubmit-iLabel" for="verifyCode">验证码</label>
</div>
<button
class="linksSubmit-submit"
type="button"
onclick="linksSubmitAction('${redirectPage}')"
>
提交链接
</button>
</div>
</form>
<script>
function getCSSVariableValue(variable) {
return getComputedStyle(document.documentElement)
.getPropertyValue(variable)
.trim();
}
function checkInput(e) {
var inputValue = e.value.trim();
var isValid = false;
var successColor = getCSSVariableValue("--success-color");
var warningColor = getCSSVariableValue("--warning-color");
if (inputValue === "" && e.required) {
e.parentNode.querySelector(".linksSubmit-iLabel").style.transform = "";
e.parentNode.querySelector(".linksSubmit-iLabel").style.color = "";
e.parentNode.querySelector(".linksSubmit-cut").style.transform = "";
var inputLabel = e.parentNode.querySelector(
".linksSubmit-iLabel",
).innerHTML;
linksSubmitToast(inputLabel + "不能为空", 2000);
} else {
e.parentNode.querySelector(".linksSubmit-iLabel").style.transform =
"translateY(-30px) translateX(10px) scale(0.75)";
e.parentNode.querySelector(".linksSubmit-iLabel").style.color =
successColor;
e.parentNode.querySelector(".linksSubmit-cut").style.transform =
"translateY(8px)";
if (e.type === "url") {
isValid = validateUrl(inputValue);
} else if (e.type === "email") {
isValid = validateEmail(inputValue);
} else {
isValid = true;
}
if (!isValid && e.required) {
console.log("输入值无效", e);
e.parentNode.querySelector(".linksSubmit-iLabel").style.color =
warningColor;
var inputLabel = e.parentNode.querySelector(
".linksSubmit-iLabel",
).innerHTML;
linksSubmitToast(inputLabel + "格式不正确", 2000);
}
}
}
</script>
:root {
--border-radius: 12px;
--background-color: #aa9d9d;
--input-background-color: #f0f0f0;
--text-color: black;
--info-color: #606060;
--warning-color: #dc2f55;
--success-color: #a9f140;
--tip-color: #50d2d4;
--button-color: #08d;
--button-active-color: #06b;
}
/* 气泡提示框样式 */
.linksSubmit-toast {
font-family:'siyuan';
max-width: 60%;
min-width: 150px;
padding: 0 14px;
height: 40px;
color: rgb(255, 255, 255);
line-height: 40px;
text-align: center;
border-radius: 4px;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 999999;
background: rgba(0, 0, 0, 0.7);
font-size: 16px;
transition: opacity 0.5s ease-in, transform 0.5s ease-in;
}
.linksSubmit-toast-hide {
opacity: 0;
transform: translate(-50%, -50%) scale(0.9);
}
.linksSubmit-form {
background-color: var(--background-color);
border-radius: 20px;
box-sizing: border-box;
padding: 20px;
width: 80%;
max-width: 600px;
margin: 120px auto;
.linksSubmit-title {
color: var(--text-color);
font-family: sans-serif;
font-size: 36px;
font-weight: 600;
margin-top: 20px;
}
.linksSubmit-subtitle {
color: var(--text-color);
font-family: sans-serif;
font-size: 16px;
font-weight: 600;
margin-top: 10px;
}
.linksSubmit-input-container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
margin-top: 30px;
gap: 20px;
}
.linksSubmit-input-option {
position: relative;
width: calc(50% - 10px);
}
@media (max-width: 600px) {
.linksSubmit-input-option {
width: 100%;
}
}
.description {
width: 100%;
}
.linksSubmit-input {
background-color: var(--input-background-color);
border-radius: var(--border-radius);
border: 0;
box-sizing: border-box;
color: var(--text-color);
font-size: 18px;
width: 100%;
height: 52px;
padding: 10px 20px;
outline: 0;
}
textarea.linksSubmit-input {
resize: vertical;
height: 70px;
}
select.linksSubmit-input {
appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
padding-right: 30px;
background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23eee"><path d="M7 10l5 5 5-5z"/></svg>');
background-repeat: no-repeat;
background-position: right 10px center;
background-size: 24px;
}
.linksSubmit-cut {
background-color: var(--background-color);
border-radius: 10px;
height: 20px;
left: 20px;
position: absolute;
top: -20px;
transform: translateY(0);
transition: transform 200ms;
width: 68px;
}
.linksSubmit-cut-short {
width: 55px;
}
.linksSubmit-iLabel {
font-family: sans-serif;
left: 20px;
line-height: 14px;
pointer-events: none;
position: absolute;
transform-origin: 0 50%;
transition: transform 200ms, color 200ms;
top: 20px;
}
.linksSubmit-iLabel-tip {
color: var(--tip-color);
font-size: 12px;
margin-left: 4px;
}
.linksSubmit-input:focus ~ .linksSubmit-cut {
transform: translateY(8px);
}
.linksSubmit-input:focus ~ .linksSubmit-iLabel, .linksSubmit-input:not(:placeholder-shown) ~ .linksSubmit-iLabel {
transform: translateY(-30px) translateX(10px) scale(0.75);
}
.linksSubmit-input:not(:focus) ~ .linksSubmit-iLabel {
color: var(--info-color);
}
.linksSubmit-input:focus ~ .linksSubmit-iLabel {
color: var(--tip-color);
}
.linksSubmit-submit {
background-color: var(--button-color);
border-radius: var(--border-radius);
border: 0;
box-sizing: border-box;
color: var(--text-color);
cursor: pointer;
font-size: 18px;
height: 50px;
text-align: center;
width: 100%;
margin-top: 20px;
}
.linksSubmit-submit:active {
background-color: var(--button-active-color);
}
.linksSubmit-verifyCode {
width: calc(60% - 10px);
display: inline-block;
}
.linksSubmit-verifyCodeDiv {
display: inline-block;
width: calc(40% - 10px);
vertical-align: top;
height: 48px;
}
.linksSubmit-verifyCodeImg {
pointer-events: none;
user-select: none;
touch-action: none;
width: 100%;
height: 100%;
margin-top: 0;
margin-bottom: -10px;
border-radius: var(--border-radius);
cursor: pointer;
display: block;
}
.linksSubmit-verifyCodeImg:hover {
transform: scale(1.05);
}
.linksSubmit-verifyCodeImg-refresh {
display: block;
text-align: center;
color: var(--button-color);
margin-top: 5px;
cursor: pointer;
font-size: 12px;
}
.linksSubmit-verifyCodeBtn {
background-color: var(--button-color);
border: 0;
border-radius: 12px;
color: var(--text-color);
cursor: pointer;
font-size: 16px;
width: 100%;
height: 50px;
}
.linksSubmit-title-container {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px 20px 0 20px;
}
.linksSubmit-left-title {
align-items: center;
}
.linksSubmit-card {
height: 80px;
padding: 0.5rem;
background: rgba(198, 198, 198, 0.34);
border-radius: 8px;
backdrop-filter: blur(5px);
border-bottom: 3px solid rgba(255, 255, 255, 0.44);
border-left: 2px rgba(255, 255, 255, 0.545) outset;
/*box-shadow: -40px 50px 30px rgba(0, 0, 0, 0.28);*/
transform: skewX(10deg);
transition: 0.4s;
overflow: hidden;
color: var(--text-color);
}
.linksSubmit-card:hover {
height: auto;
transform: skew(0deg);
}
.linksSubmit-card-align {
display: flex;
flex-direction: row;
gap: 5px;
align-self: flex-start;
}
.linksSubmit-card-red, .linksSubmit-card-yellow, .linksSubmit-card-green {
width: 10px;
height: 10px;
border-radius: 50%;
box-shadow: -5px 5px 5px rgba(0, 0, 0, 0.28);
}
.linksSubmit-card-red {
background-color: #ff605c;
}
.linksSubmit-card-yellow {
background-color: #ffbd44;
}
.linksSubmit-card-green {
background-color: #00ca4e;
}
.linksSubmit-card .linksSubmit-card-title {
text-align: center;
color: rgb(218, 244, 237);
text-shadow: -10px 5px 10px rgba(0, 0, 0, 0.573);
}
.linksSubmit-card .linksSubmit-card-content {
text-align: left;
margin: 0.5rem;
color: rgb(218, 244, 237);
text-shadow: -10px 5px 10px rgba(0, 0, 0, 0.573);
font-size: 14px;
line-height: 1.5;
word-break: break-all;
}
.linksSubmit-card .linksSubmit-card-btn {
padding: 12.5px 30px;
border: 0;
border-radius: 100px;
background-color: #606569;
color: rgb(218, 244, 237);
font-weight: bold;
transition: all 0.5s;
}
.linksSubmit-card .linksSubmit-card-btn:hover {
cursor: pointer;
background-color: #6a6f72;
box-shadow: 0 0 20px rgba(151, 169, 111, 0.31);
transform: scale(1.1);
}
}
:root {
--border-radius: 12px; /* 全局圆角半径 */
--background-color: #9c9090; /* 背景颜色 */
--input-background-color: #f0f0f0; /* 输入框背景颜色 */
--text-color: black; /* 文字颜色 */
--info-color: #606060; /* 信息提示颜色 */
--warning-color: #dc2f55; /* 警告提示颜色 */
--success-color: #a9f140; /* 成功提示颜色 */
--tip-color: #50d2d4; /* 提示颜色 */
--button-color: #08d; /* 按钮颜色 */
--button-active-color: #06b; /* 按钮激活状态颜色 */
}