在线Base64加解密HTML源码

程序源码 阅读 14

Base64加解密HTML自己编写的添加了pc端和手机端自适应,反复测试过没有任何问题现在分享给各位,渐变背景我已经在源码里标注自行效果。


<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Base64加解密</title>
<style>
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(to right, #c7ffc7, #fff2cc, #c7ffff, #cfe2f3); /* 渐变背景颜色在此处效果使用rgb工具 */
}
.card {
    width: 80%;
    max-width: 600px;
    background-color: white;
    border-radius: 15px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15), 0 6px 20px rgba(0,0,0,0.1);
    padding: 20px;
    transition: transform 0.3s;
    position: relative;
}
.card:hover {
    transform: translateY(-5px);
}
textarea {
    width: 100%;
    max-width: 100%;
    height: 150px;
    margin-bottom: 20px;
    padding: 10px;
    font-size: 1rem;
    border: 2px solid #ccc;
    border-radius: 4px;
    background-color: white;
    transition: transform 0.3s, box-shadow 0.3s, border-color 0.3s;
    box-sizing: border-box;
}
textarea:hover, textarea:focus {
    transform: scale(1.02);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    border-color: #44d431;
}
textarea:focus {
    outline: none;
}
.controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}
.btn32 {
    height: 70px;
    padding: 0 20px;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.8);
    border-radius: 10px;
    background-color: #f2fff7;
    font-size: 14px;
    font-weight: 700;
    color: #44d431;
    box-shadow: 6px 6px 16px rgba(0,0,0,0.2), -6px -6px 16px rgba(255,255,255,0.8), inset 0px 0px 0px rgba(0,0,0,0.2), inset 0px 0px 0px rgba(255,255,255,0.8);
    transition: 0.2s;
}
.btn32:hover {
    color: #3034d4;
    background-color: #f2f3ff;
    border: 1px solid rgba(255,255,255,1);
    box-shadow: 0px 0px 0px rgba(0,0,0,0.2), 0px 0px 0px rgba(255,255,255,0.8), inset 6px 6px 12px rgba(0,0,0,0.2), inset -6px -6px 12px rgba(255,255,255,0.8);
    transform: translateY(10px) scale(0.98);
}
@media(max-width:600px) {
    textarea {
        width: 95%;
        height: 200px;
    }
    button {
        font-size: 0.9rem;
    }
    .controls {
        flex-direction: column;
    }
}
</style>
</head>
<body>
<h1>Base64加解密</h1>
<div class="card">
    <textarea id="inputText" placeholder="输入文本..."></textarea>
    <div class="controls">
        <button class="btn32" onclick="encodeBase64()">编码</button>
        <button class="btn32" onclick="decodeBase64()">解码</button>
        <button class="btn32" onclick="swap()">↑交换</button>
        <button class="btn32" onclick="copyOutput()">复制结果</button>
        <button class="btn32" onclick="clearFields()">清空</button>
    </div>
    <h2>结果:</h2>
    <textarea id="outputText" readonly></textarea>
</div>
<script>
function encodeBase64() {
    const inputText = document.getElementById("inputText").value;
    const encodedText = btoa(unescape(encodeURIComponent(inputText)));
    document.getElementById("outputText").value = encodedText;
}
function decodeBase64() {
    const inputText = document.getElementById("inputText").value;
    try {
        const decodedText = decodeURIComponent(escape(atob(inputText)));
        document.getElementById("outputText").value = decodedText;
    } catch (e) {
        document.getElementById("outputText").value = "解码失败,输入的编码可能不正确。";
    }
}
function copyOutput() {
    const outputText = document.getElementById("outputText");
    outputText.select();
    outputText.setSelectionRange(0, 99999);
    document.execCommand("copy");
    alert("结果已复制到剪贴板!");
}
function swap() {
    const inputText = document.getElementById("inputText");
    const outputText = document.getElementById("outputText");
    const temp = inputText.value;
    inputText.value = outputText.value;
    outputText.value = temp;
}
function clearFields() {
    document.getElementById("inputText").value = "";
    document.getElementById("outputText").value = "";
}
</script>
</body>
</html>

相关推荐

用户留言

尚未登录无法发表查看留言点击登录

HI ! 请登录

立即登录
免费壁纸小程序
免费壁纸小程序