首页 > 其他分享 >前端项目-记事本制作

前端项目-记事本制作

时间:2023-08-04 19:45:11浏览次数:29  
标签:body color border 前端 0.5 background document 制作 记事本

效果预览:

夜间模式:

日间模式:

应用的主要功能:

  • 记事功能:你可以在文本框中输入你的笔记,然后点击“保存”按钮,你的笔记就会被保存下来。你可以随时查看和删除你的笔记。
  • 夜间模式:我们的应用支持夜间模式,你可以点击“切换模式”按钮来切换夜间模式和日间模式。夜间模式有助于在光线较暗的环境中保护你的眼睛。
  • 自定义背景:你可以选择一张图片作为应用的背景。只需要点击“选择背景”按钮,然后选择你喜欢的图片,这个图片就会被设置为背景。我们还提供了一个半透明的覆盖层,可以让背景图片变得更加柔和。
  • 响应式设计:我们的应用使用了响应式设计,这意味着它可以在任何设备上正常工作,无论是桌面电脑、笔记本电脑、平板电脑还是手机。
  • 本地存储:我们的应用使用了本地存储技术,这意味着你的笔记、模式选择和背景图片都会被保存在你的设备上,即使你关闭了浏览器或者重启了设备,你的设置和笔记也不会丢失。

代码解析:

        body, textarea {
            font-family: 'Arial Rounded MT', Arial, sans-serif;
            padding: 20px;
            background: white;
            background: linear-gradient(to right, white, #f3f3f8);
            background-size: cover;
            display: flex;
            flex-direction: column;
            align-items: center;
            height: 100vh;
            margin: 0;
            color: #333;
            font-size: 18px;
            line-height: 1.6;
            transition: background 0.5s, color 0.5s;
            opacity: 0;
            animation: fadeIn 2s ease-in forwards;
        }

        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }

        body.night {
            background: #333;
            background: linear-gradient(to right, #333, #555);
            color: #ddd;
        }

        textarea {
            width: 80%;
            height: 100px;
            padding: 15px;
            box-sizing: border-box;
            margin-bottom: 10px;
            font-size: 16px;
            border: 2px solid #ccc;
            border-radius: 4px;
            background-color: #f8f8f8;
            resize: none;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
            transition: background 0.5s, border 0.5s;
        }

        body.night textarea {
            background-color: #555;
            border-color: #888;
            color: #ddd;
        }

        button {
            display: block;
            width: 100px;
            margin: 20px auto;
            padding: 10px;
            font-size: 18px;
            background-color: #4CAF50; /* Green */
            border: none;
            color: white;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            margin: 4px 2px;
            cursor: pointer;
            border-radius: 12px;
            transition: all 0.3s;
        }

        button:hover {
            transform: scale(1.1);
        }

        body.night button {
            color: #ddd;
        }

        #savedNotes {
            font-size: 16px;
            color: #333;
            width: 80%;
            transition: color 0.5s;
        }

        body.night #savedNotes {
            color: #ddd;
        }

        .note {
            position: relative;
            padding: 10px;
            border: 1px solid #ccc;
            margin-bottom: 10px;
            transition: border 0.5s;
        }

        body.night .note {
            border-color: #888;
        }

        .deleteButton {
            position: absolute;
            top: 0;
            right: 0;
            background-color: red;
            color: white;
            border: none;
            cursor: pointer;
            border-radius: 50%;
            width: 20px;
            height: 20px;
            opacity: 0.7;
            font-size: 14px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
# 鼠标放在哪里的时候,不透明度设置为1
        .deleteButton:hover {
            opacity: 1;
        }
# 夜间模式删除按钮的颜色设置
        body.night .deleteButton {
            color: #ddd;
        }
# 切换夜间、白天模式的按钮
        #modeSwitch {
            position: fixed;
            top: 20px;
            right: 20px;
            cursor: pointer;
            background-color: #4CAF50;
            color: white;
            border: none;
            padding: 10px 20px;
            font-size: 16px;
            border-radius: 12px;
            transition: background-color 0.5s, color 0.5s;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        body.night #modeSwitch {
            background-color: #555;
            color: #ddd;
        }

        @media (max-width: 600px) {
            textarea, #savedNotes {
                width: 100%;
            }
        }
        #backgroundInput {
            display: none;
        }
# 这部分是初始及选择图片后背景的设计:
        #backgroundLabel {
            position: fixed;
            top: 20px;
            left: 20px;
            cursor: pointer;
            background-color: #4CAF50;
            color: white;
            border: none;
            padding: 10px 20px;
            font-size: 16px;
            border-radius: 12px;
            transition: background-color 0.5s, color 0.5s;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        body.night #backgroundLabel {
            background-color: #555;
            color: #ddd;
        }
# 这部分是覆盖图层用于柔滑背景图片的代码:
        body::before {
            content: "";
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(255, 255, 255, 0.5);
            z-index: -1;
        }

        body.night::before {
            background: rgba(0, 0, 0, 0.5);
        }
<body>
    <textarea id="noteText" rows="10" cols="30"></textarea>
    <button id="saveButton">保存</button>
    <div id="savedNotes"></div>
    <button id="modeSwitch">切换模式</button>
    <input type="file" id="backgroundInput" accept="image/*">
    <label for="backgroundInput" id="backgroundLabel">选择背景</label>
    <script>
# 采用Json parse来进行数据的存储及读取。
        var notes = JSON.parse(localStorage.getItem('notes')) || [];
        var nightMode = localStorage.getItem('nightMode') === 'true';
        var backgroundImage = localStorage.getItem('backgroundImage');
# 显示出来所有的已经保存的记事本内容
        // Display all saved notes
        document.getElementById('savedNotes').innerHTML = notes.map(function(note, index) {
            return '<div class="note"><p>' + note + '</p><button class="deleteButton" data-index="' + index + '">X</button></div>';
        }).join('');

        document.getElementById('saveButton').addEventListener('click', function() {
            var noteText = document.getElementById('noteText').value;
            notes.push(noteText);
            localStorage.setItem('notes', JSON.stringify(notes));
            document.getElementById('savedNotes').innerHTML += '<div class="note"><p>' + noteText + '</p><button class="deleteButton" data-index="' + (notes.length - 1) + '">X</button></div>';
            document.getElementById('noteText').value = '';
        });

        document.getElementById('savedNotes').addEventListener('click', function(e) {
            if(e.target.className === 'deleteButton') {
                var index = e.target.getAttribute('data-index');
                notes.splice(index, 1);
                localStorage.setItem('notes', JSON.stringify(notes));
                e.target.parentElement.remove();
            }
        });

        document.getElementById('modeSwitch').addEventListener('click', function() {
            nightMode = !nightMode;
            localStorage.setItem('nightMode', nightMode);
            document.body.className = nightMode ? 'night' : '';
        });

        document.getElementById('backgroundInput').addEventListener('change', function(e) {
            var file = e.target.files[0];
            var reader = new FileReader();
            reader.onloadend = function() {
                document.body.style.backgroundImage = 'url(' + reader.result + ')';
                localStorage.setItem('backgroundImage', reader.result);
            }
            if (file) {
                reader.readAsDataURL(file);
            } else {
                document.body.style.backgroundImage = '';
            }
        });

        // Set initial mode and background
        document.body.className = nightMode ? 'night' : '';
        if (backgroundImage) {
            document.body.style.backgroundImage = 'url(' + backgroundImage + ')';
        }
    </script>
</body>

标签:body,color,border,前端,0.5,background,document,制作,记事本
From: https://www.cnblogs.com/D876887913/p/17606834.html

相关文章

  • 网站前端性能分析
    一速度与功能,哪个更重要二网站性能与收入三网站速度与用户流失四Web性能优化法则五国内性能分析工具—基调系统介绍六国际站的优化实践七改进建议八评分规则及优化一 速度与功能,哪个更重要 1.网站最基本的东西是什么? 内容再丰富的网站,如果慢到无法访问也......
  • 前端分页和搜索
    需求一般来说,分页和搜索都是后端处理的。但有时候后端没处理,就只能前端处理了。当然这要在数据量不大的情况下,否则会性能消耗很大。分析使用setTimeout(()=>{},1000)模拟接口调用;数据总条数total是符合搜索结果的数据总条数;使用分页组件,搭配arr.slice()返回当前页......
  • 小狐狸GPT付费源码-WEB版前端的监控代码
    今天搭建了下小狐狸的WEB版,里面有个隐藏的js代码调用外部接口可以看到下面的代码 会把当前的域名调用外部接口传递过去  ......
  • 歌谣学前端之react三个api之一续集
    前言我是歌谣我有个兄弟巅峰的时候排名c站总榜19叫前端小歌谣曾经我花了三年的时间创作了他现在我要用五年的时间超越他今天又是接近兄弟的一天人生难免坎坷大不了从头再来歌谣的意志是永恒的放弃很容易但是坚持一定很酷微信公众号前端小歌谣关注公众号带你进入前端学......
  • 植物大战僵尸修改器制作--从入门到入土
    目录基础准备基址偏移表常规项目卡槽植物种植无冷却无限阳光浓雾透视基本原理HOOK除雾代码种植植物基本原理远程线程注入dll函数远程线程卸载dll函数关键dll函数失败代码远程线程代码注入(推荐)种植僵尸基本原理种植僵尸函数--dll注入版远程代码注入版完整代码参考资料基础准备......
  • 前端性能优化的利器 ——— 浅谈JavaScript中的防抖和节流
    防抖和节流函数是工作中两种常用的前端性能优化函数,今天我就来总结一下什么是防抖和节流,并详细说明一下如何在工作中应用防抖和节流函数什么是防抖和节流?在JavaScript中,防抖(debounce)和节流(throttle)是用来限制函数执行频率的两种常见技术。防抖(debounce)是指在某个时间段内......
  • 前端项目时因chunk-vendors过大导致首屏加载太慢,Vue Build时chunk-vendors的优化方案
    1、compression-webpack-plugin插件打包.gz文件安装插件也可以指定版本 我这里下载的是1.1.2版本的,试过更高的版本会有ES6语法的报错,因为我node使用的是v12,如果node版本更高可以尝试更高版本npminstall--save-devcompression-webpack-pluginnpminstall--save-devc......
  • RTSP流媒体服务器LntonNVR(源码版)平台前端打包出现“UglifyJsPlugin”报错的问题解决
    LntonNVR既有软件版也有硬件版,平台基于RTSP/Onvif协议将前端设备接入,可实现的视频能力有视频监控直播、录像、视频转码分发、检索与回放、云存储、智能告警、国标级联等。平台可将接入的视频流进行转码分发,对外输出的视频流格式包括RTSP、RTMP、HTTP-FLV、WS-FLV、HLS、WebRTC等。......
  • web前端技能方法总结(css、js、jquery、html)(2)
    创建链接块display:block;列表样式在一个无序列表中,列表项的标志(marker)是出现在各列表项旁边的圆点。在有序列表中,标志可能是字母、数字或另外某种计数体系中的一个符号。要修改用于列表项的标志类型,可以使用属性list-style-type:ul{list-style-type:square;}1上面的声明把......
  • 制作一张亮丽的明信片太容易了!
    无论您是推广您的业务、宣传您的活动,还是创建一个有趣的个人管道来分享您的作品,您都可以从一张很棒的明信片开始。想想你上一次在礼品店的情景:还记得那一排普通、千篇一律单调的明信片吗?跳过这商业味重重的框框,创造一些别出心裁的东西!用VisualParadigmInfographic设计你自己的......