总结
前端考核刚刚结束,发现自身有很多问题。网页制作方面很多能复用的地方都没复用,就硬写,导致代码整体效果不好。JS方面应该多试试写函数和用for循环来简化代码,不经常用函数会导致以后写的不习惯,也会导致代码不够简化。
https://blog.csdn.net/Flying____fish/article/details/114789389 和这位大佬说的一样,“工欲善其事,必先利其器”。应该用自己顺手的工具,可以提升写代码的速度,也能使逻辑更缜密。
&nesp;&nesp;蓝桥杯马上就要开始了,虽然在寒假期间没怎么练习算法,但是在学校的几天练习真的能感觉到自己的算法有所提升。以前不会的如今也解开了。
&nesp;&nesp;另外在考核期间做了两个3D旋转轮播图。代码奉上:
- 轮播图一:
- 开启定时器自动旋转
- 左右切换按钮
html代码:命名为轮播图.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>轮播图</title>
<link rel="stylesheet" href="轮播图.css">
</head>
<body>
<table></table>
<div class="cotain_banner">
<div class="banner">
<div>
<h2>小米商城</h2>
<p>当前时间</p>
<span class="blackBox mar"></span>
<span class="fl dian">:</span>
<span class="blackBox"></span>
<span class="fl dian">:</span>
<span class="blackBox"></span>
</div>
<div>
<img src="img/0f5c49925f3a7d5157b8ac7f4f66b34b.webp" alt="" width="auto" height="200">
</div>
<div>
<img src="img/85fe83512254832000635fb15f048df5.webp" alt="" width="auto" height="200">
</div>
<div>
<img src="img/aebcb8f7d8c6ddaa754bfbb701a38cbf.webp" alt="" width="auto" height="200">
</div>
<div>
<img src="img/c7fd00fa846cefaaa73572ea55832854.jpg" alt="" width="auto" height="200">
</div>
<div>
<img src="img/e023dd94c146d0f27f7ae8e98213abff.webp" alt="" width="auto" height="200">
</div>
</div>
<a class="left" href="javascript:;">
<i></i>
</a>
<a class="right" href="javascript:;">
<i></i>
</a>
</div>
<script src="轮播图.js"></script>
</body>
</html>
css代码:命名为轮播图.css
body{
perspective: 1000px;/*透视效果*/
}
a{
text-decoration: none;
}
@font-face {
font-family: 'icomoon';
src: url('fonts/icomoon.eot?rgq97g');
src: url('fonts/icomoon.eot?rgq97g#iefix') format('embedded-opentype'),
url('fonts/icomoon.ttf?rgq97g') format('truetype'),
url('fonts/icomoon.woff?rgq97g') format('woff'),
url('fonts/icomoon.svg?rgq97g#icomoon') format('svg');
font-weight: normal;
font-style: normal;
font-display: block;
}
i{
font-family: "icomoon";
font-style: normal;
}
.banner{
width: 300px;
height:200px;
margin: 100px auto;
position: relative;
transform-style: preserve-3d;/*让父元素里面的盒子以3D效果显示*/
transition:all 0.3s linear;/*linear匀速*/
}
.contain_banner{
width:300px;
height:200px;
margin: 0 auto;
position: relative;
}
.banner div{
width:300px;
height:200px;
position: absolute;
top: 0;
left: 0;
}
.banner div:nth-child(1){
width:450px;
height:160px;
margin-top: 10px;
margin-left: 25px;
background-color: #f1eded;
border: 1px solid #ff6700;
transform: rotateY(0deg) translateZ(500px);/*translateZ使用时要给body添加以上元素*/
text-align: center;
color: #ff6700;
padding: 0 150px;
box-sizing: border-box;
}
.banner div:nth-child(2){
transform: rotateY(60deg) translateZ(400px);
}
.banner div:nth-child(3){
transform: rotateY(120deg) translateZ(400px);
}
.banner div:nth-child(4){
transform: rotateY(180deg) translateZ(400px);
}
.banner div:nth-child(5){
transform: rotateY(240deg) translateZ(400px);
}
.banner div:nth-child(6){
transform: rotateY(300deg) translateZ(400px);
}
/*轮播图左右按钮*/
.left{
position: absolute;
top: 50%;
left: 0;
font-size: 40px;
color: #ff6700;
}
.right{
position: absolute;
top: 50%;
right:0;
font-size: 40px;
color: #ff6700;
}
/*当前时间*/
.blackBox{
display: block;
width:40px !important;
height:40px !important;
background-color: #605751;
float: left;
text-align: center;
line-height: 40px;
}
.fl{
float: left;
}
js代码:命名为轮播图.js
/*获取轮播图的元素*/
var banner=document.getElementsByClassName("banner")[0];
/*定时器*/
timer();
timert();
/*左右点击*/
var left=document.getElementsByClassName("left")[0];
var right=document.getElementsByClassName("right")[0];
right.onclick=function(){
clearInterval(timere);
clearInterval(timer_t);
index+=60;
banner.style.transform="rotateY("+index+"deg)";
timer();
timert();
}
left.onclick=function(){
clearInterval(timere);
clearInterval(timer_t);
index-=60;
banner.style.transform="rotateY("+index+"deg)";
timer();
timert();
}
/*当前时间*/
var blackBox=document.getElementsByClassName("blackBox");
setInterval(function() {
var dater = new Date();
var hours = dater.getHours();
var minutes = dater.getMinutes();
var seconds = dater.getSeconds();
if( minutes < 10) {
blackBox[1].innerHTML = "0" + minutes;
} else {
blackBox[1].innerHTML = minutes;
}
if(seconds < 10) {
blackBox[2].innerHTML = "0" + seconds;
} else {
blackBox[2].innerHTML = seconds;
}
if(hours < 10) {
blackBox[0].innerHTML = "0" + hours;
} else {
blackBox[0].innerHTML = hours;
}
// miao.innerHTML=60-seconds;
}, 1000);
/*定时器function*/
var index=0;
var timere;
var timer_t;
function timer(){
timere=setInterval(function(){
index+=60;
banner.style.transform="rotateY("+index+"deg)";
clearInterval(timere);
},2000);
}
function timert(){
timer_t=setInterval(function(){
banner.style.transform="rotateY("+index+"deg)";
timer();
},4000);
}
- 轮播图二
html文件:命名为轮播图.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>轮播图</title>
<link rel="stylesheet" href="轮播图.css">
</head>
<body>
<table></table>
<div class="cotain_banner">
<div class="banner">
<div>
<h2>小米商城</h2>
<p>当前时间</p>
<span class="blackBox mar"></span>
<span class="fl dian">:</span>
<span class="blackBox"></span>
<span class="fl dian">:</span>
<span class="blackBox"></span>
</div>
<div>
<img src="img/0f5c49925f3a7d5157b8ac7f4f66b34b.webp" alt="" width="300" height="200">
</div>
<div>
<img src="img/85fe83512254832000635fb15f048df5.webp" alt="" width="300" height="200">
</div>
<div>
<img src="img/aebcb8f7d8c6ddaa754bfbb701a38cbf.webp" alt="" width="300" height="200">
</div>
<div>
<img src="img/c7fd00fa846cefaaa73572ea55832854.jpg" alt="" width="300" height="200">
</div>
<div>
<img src="img/e023dd94c146d0f27f7ae8e98213abff.webp" alt="" width="300" height="200">
</div>
</div>
<a class="left" href="javascript:;">
<i></i>
</a>
<a class="right" href="javascript:;">
<i></i>
</a>
</div>
<script src="轮播图.js"></script>
</body>
</html>
css文件:命名为轮播图.css
body{
perspective: 1000px;/*透视效果*/
}
a{
text-decoration: none;
}
@font-face {
font-family: 'icomoon';
src: url('fonts/icomoon.eot?rgq97g');
src: url('fonts/icomoon.eot?rgq97g#iefix') format('embedded-opentype'),
url('fonts/icomoon.ttf?rgq97g') format('truetype'),
url('fonts/icomoon.woff?rgq97g') format('woff'),
url('fonts/icomoon.svg?rgq97g#icomoon') format('svg');
font-weight: normal;
font-style: normal;
font-display: block;
}
i{
font-family: "icomoon";
font-style: normal;
}
.banner{
width: 300px;
height:200px;
margin: 100px auto;
position: relative;
transform-style: preserve-3d;/*让父元素里面的盒子以3D效果显示*/
transition:all 0.3s linear;/*linear匀速*/
}
.contain_banner{
width:300px;
height:200px;
margin: 0 auto;
position: relative;
}
.banner div{
width:300px;
height:200px;
position: absolute;
top: 0;
left: 0;
}
.banner div:nth-child(1){
width: 300px;
height:200px;
background-color: #f1eded;
border: 1px solid #ff6700;
transform: rotateY(0deg) translateZ(500px);/*translateZ使用时要给body添加以上元素*/
text-align: center;
color: #ff6700;
padding: 0 80px;
box-sizing: border-box;
}
.banner div:nth-child(2){
transform: rotateY(60deg) translateZ(400px);
}
.banner div:nth-child(3){
transform: rotateY(120deg) translateZ(400px);
}
.banner div:nth-child(4){
transform: rotateY(180deg) translateZ(400px);
}
.banner div:nth-child(5){
transform: rotateY(240deg) translateZ(400px);
}
.banner div:nth-child(6){
transform: rotateY(300deg) translateZ(400px);
}
/*轮播图左右按钮*/
.left{
position: absolute;
top: 50%;
left: 0;
font-size: 40px;
color: #ff6700;
}
.right{
position: absolute;
top: 50%;
right:0;
font-size: 40px;
color: #ff6700;
}
/*当前时间*/
.blackBox{
display: block;
width:40px !important;
height:40px !important;
background-color: #605751;
float: left;
text-align: center;
line-height: 40px;
}
.fl{
float: left;
}
js文件:命名为轮播图.js
/*获取轮播图的元素*/
var banner=document.getElementsByClassName("banner")[0];
/*定时器*/
timer();
timert();
/*左右点击*/
var left=document.getElementsByClassName("left")[0];
var right=document.getElementsByClassName("right")[0];
right.onclick=function(){
clearInterval(timere);
clearInterval(timer_t);
index+=60;
banner.style.transform="rotateY("+index+"deg)";
timer();
timert();
}
left.onclick=function(){
clearInterval(timere);
clearInterval(timer_t);
index-=60;
banner.style.transform="rotateY("+index+"deg)";
timer();
timert();
}
/*当前时间*/
var blackBox=document.getElementsByClassName("blackBox");
setInterval(function() {
var dater = new Date();
var hours = dater.getHours();
var minutes = dater.getMinutes();
var seconds = dater.getSeconds();
if( minutes < 10) {
blackBox[1].innerHTML = "0" + minutes;
} else {
blackBox[1].innerHTML = minutes;
}
if(seconds < 10) {
blackBox[2].innerHTML = "0" + seconds;
} else {
blackBox[2].innerHTML = seconds;
}
if(hours < 10) {
blackBox[0].innerHTML = "0" + hours;
} else {
blackBox[0].innerHTML = hours;
}
// miao.innerHTML=60-seconds;
}, 1000);
/*定时器function*/
var index=0;
var timere;
var timer_t;
function timer(){
timere=setInterval(function(){
index+=60;
banner.style.transform="rotateY("+index+"deg)";
clearInterval(timere);
},2000);
}
function timert(){
timer_t=setInterval(function(){
banner.style.transform="rotateY("+index+"deg)";
timer();
},4000);
}
一起加油吧!!!