HTML:
<div class="boxAll">
<div class="pac-man" id="pac-man"></div>
<div class="pac-man-mouth0" id="pac-man-mouth0"></div>
<div class="pac-man-mouth1" id="pac-man-mouth1"></div>
<div class="beans">
<div class="radBody" id="radBody">
<div class="radbox" id="radbox">
<div class="rad0"></div>
<div class="rad0"></div>
<div class="rad0"></div>
<div class="rad0"></div>
</div>
</div>
</div>
</div>
CSS:
* {
margin:0;
padding:0;
text-decoration:none;
}
html {
height:100%;
}
body {
height:100%;
display:flex;
justify-content:center;
align-items:center;
position:relative;
}
.boxAll {
width:250px;
height:120px;
/* background:rgba(165,42,42,0.164);
*/
position:relative;
}
.pac-man {
width:100px;
height:100px;
background:rgb(215,52,88);
position:absolute;
top:10px;
left:10px;
border-radius:50%;
clip:rect(0,50px,100px,0);
}
.pac-man-mouth0 {
width:100px;
height:100px;
position:absolute;
top:10px;
left:10px;
border-radius:50%;
background:rgb(215,52,88);
clip:rect(0,100px,50px,0);
/* transform:rotate(0deg);
*/
/* transform:rotate(-35deg);
*/
}
.pac-man-mouth1 {
width:100px;
height:100px;
position:absolute;
top:10px;
left:10px;
border-radius:50%;
background:rgb(215,52,88);
clip:rect(50px,100px,100px,0);
/* transform:rotate(35deg);
*/
}
.beans {
width:190px;
height:20px;
position:absolute;
left:60px;
top:50px;
overflow:hidden;
z-index:-999;
}
.radNull {
width:20px;
height:20px;
float:left;
}
.radBody {
width:300px;
height:20px;
float:left;
}
.radbox {
width:auto;
height:20px;
float:left;
/* background:rgb(255,81,0);
*/
}
.rad0 {
width:20px;
height:20px;
border-radius:50%;
background:rgb(230,65,101);
margin-right:18px;
float:left;
}
.bottom {
width:100%;
height:30px;
background-color:rgba(255,248,220,.5);
position:absolute;
bottom:0;
display:flex;
justify-content:center;
font-size:12px;
align-items:center;
}
.bottom a,span {
color:darkgrey;
margin:0 10px;
}
.bottom a:hover {
color:#999;
}
.bottom a:focus {
color:#999;
}
JS:
//得到吃豆人的身体
var pmm0 = document.getElementById('pac-man-mouth0'),
pmm1 = document.getElementById('pac-man-mouth1');
var Timer, Timer1, Timer2 = null;
var radBody = document.getElementsByClassName('radBody')[0];
var radbox = document.getElementsByClassName('radbox')[0];
let speed = -10;
window.onload = function() {
Timer = setInterval(function() {
runOne()
}, 600)
Timer = setInterval(function() {
runTwo()
}, 1200)
function runOne() {
pmm0.style.transition = 'all ease .7s';
pmm0.style.transform = "rotate(-43deg)";
pmm1.style.transition = 'all ease .7s';
pmm1.style.transform = "rotate(43deg)";
}
function runTwo() {
pmm0.style.transition = 'all ease 1s';
pmm0.style.transform = "rotate(43deg)";
pmm1.style.transition = 'all ease 1s';
pmm1.style.transform = "rotate(-43deg)";
}
radbox.innerHTML = radbox.innerHTML + radbox.innerHTML;
Timer2 = setInterval(function() {
if (radBody.offsetLeft < -radBody.offsetWidth / 4) {
radBody.style.marginLeft = 0;
}
// console.log(radbox.offsetLeft)
radBody.style.marginLeft = radBody.offsetLeft + speed + 'px';
}, 300)
}