实现h5、css3便签列表如下所示,要求第一次打开便签页面时,判断localStorage是否存储有便签数据,便签本地存储可以认为存储在localStorage['note'],若localStorage['note']没有数据先通过js将便签数组数据存储到localStorage['note'],若存在数据,则从localStorage取出数据渲染到页面上,通过nth-child选择器实现对便签的背景色和字体颜色控制,标签有旋转、阴影效果,并且鼠标箭头移上便签时有相应过渡显示效果。提交整个网页文件代码块。 便签数据参考结构: [{ "noteid": 1, "noteName": "便签1", "noteContent": "便签内容1" }, { "noteid": 2, "noteName": "便签2", "noteContent": "便签内容2" }, { "noteid": 3, "noteName": "便签3", "noteContent": "便签内容3" }]
时间: 2023-11-13 08:55:55 浏览: 67
<!DOCTYPE html>
<html>
<head>
<title>便签列表</title>
<style>
.note {
width: 200px;
height: 200px;
background-color: #fff;
box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.3);
border-radius: 10px;
padding: 20px;
position: relative;
transition: all 0.3s ease-in-out;
overflow: hidden;
}
.note:hover {
transform: rotate(5deg);
box-shadow: 10px 10px 10px rgba(0, 0, 0, 0.5);
}
.note:hover .note-title {
transform: rotate(-5deg);
color: #fff;
background-color: #333;
}
.note:hover .note-content {
color: #fff;
transform: translateY(-100%);
background-color: #333;
}
.note-title {
font-size: 24px;
font-weight: bold;
text-align: center;
position: absolute;
top: 0;
left: 0;
right: 0;
padding: 10px;
background-color: #fff;
color: #333;
border-bottom: 1px solid #333;
transition: all 0.3s ease-in-out;
z-index: 1;
}
.note-content {
font-size: 16px;
line-height: 1.5;
position: absolute;
bottom: 0;
left: 0;
right: 0;
padding: 10px;
background-color: #fff;
color: #333;
transition: all 0.3s ease-in-out;
z-index: 1;
}
.note:nth-child(2n) {
background-color: #f0f0f0;
}
.note:nth-child(2n) .note-title {
background-color: #f0f0f0;
color: #333;
}
.note:nth-child(2n) .note-content {
background-color: #f0f0f0;
color: #333;
}
</style>
</head>
<body>
<div id="note-list"></div>
<script>
// 便签数据
var notes = [{
"noteid": 1,
"noteName": "便签1",
"noteContent": "便签内容1"
}, {
"noteid": 2,
"noteName": "便签2",
"noteContent": "便签内容2"
}, {
"noteid": 3,
"noteName": "便签3",
"noteContent": "便签内容3"
}];
// 检查localStorage是否存在便签数据
if (!localStorage.getItem('note')) {
// 如果不存在,则存储数据到localStorage
localStorage.setItem('note', JSON.stringify(notes));
} else {
// 如果存在,则从localStorage取出数据
notes = JSON.parse(localStorage.getItem('note'));
}
// 渲染便签列表
var noteList = document.getElementById('note-list');
notes.forEach(function(note) {
var noteDiv = document.createElement('div');
noteDiv.className = 'note';
noteDiv.innerHTML = '<div class="note-title">' + note.noteName + '</div><div class="note-content">' + note.noteContent + '</div>';
noteList.appendChild(noteDiv);
});
</script>
</body>
</html>
阅读全文