發(fā)廊燈
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>燈</title>
<style>
*{
padding: 0;margin: 0;
}
html,body{
height: 100%;
overflow: hidden;
}
#wrap{
width: 40px;
height: 300px;
border: 1px solid #000;
margin: 100px auto;
overflow: hidden;
}
#wrap > .inner{
height: 600px;
background: repeating-linear-gradient(135deg,black 0px, black 10px, white 10px, white 20px);
}
/* #wrap:hover .inner{
margin-top: -300px
}*/
</style>
</head>
<body>
<div id="wrap">
<div class="inner"></div>
</div>
<script>
var inner = document.getElementsByClassName('inner')[0]
console.log(inner)
var flag = 0
var test = function(){
if(flag === 280){
flag = 0
}
flag++
inner.style.marginTop = -flag + 'px'
// console.log(inner.style.marginTop)
}
setInterval(test,1000/60)
</script>
</body>
</html>
光斑效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>燈</title>
<style>
*{
padding: 0;margin: 0;
}
html,body{
height: 100%;
overflow: hidden;
background: #000;
text-align: center;
}
h1{
/*transition:3s;*/
margin-top: 50px;
display: inline-block;
color:rgba(255, 255, 255, .3);
font: bold 80px '微軟雅黑';
background:linear-gradient(150deg,rgba(255, 255, 255, 0) 80px,rgba(255, 255, 255, 1) 120px ,rgba(255, 255, 255, 0) 160px);
background-repeat: no-repeat;
-webkit-background-clip:text;
}
/* h1:hover{
background-position: 500px 0;
} */
</style>
</head>
<body>
<h1>圖解CSS3核心技術(shù)與實(shí)戰(zhàn)</h1>
<script>
var h1 = document.getElementsByTagName('h1')[0]
var len = h1.style.width
console.log(len)
var flag = -180
var test = function(){
if(flag > 920){
flag = -180
}
flag+=6
h1.style.backgroundPosition = flag + 'px'
// console.log(h1.style.backgroundPosition)
}
setInterval(test,1000/60)
</script>
</body>
</html>