最简单的hover写法,淡入淡出,关键在于pointer-events的使用,保证淡入淡出都有过渡效果的同时,子元素不会被父元素hover事件所影响!
function showTiShi(){var tm=0ts=document.getElementById("spanTiShi")
ts.style.display="block"
fadeIn()
function fadeIn(){
if(tm<1){
tm+=0.1
ts.style.opacity=tm
setTimeout(fadeIn,100)
}else{
setTimeout(fadeOut,5000)
}
}
function fadeOut(){
if(tm>0){
tm-=0.1
ts.style.opacity=tm
setTimeout(fadeOut,100)
}else{
ts.style.display="none"
}
}
}
<!DOCTYPE html><html>
<head>
<meta charset="utf-8">
<title>CSS3</title>
<style>
*{ padding:0margin:0font-size:12px }
.open{ width:100pxheight:100pxtext-align:centerline-height:100pxbackground-color:pinkcolor:#000border-radius:50%margin:50px autobox-shadow:0 0 10px,0 0 10px #ff0000 }
.fade{
animation:fade 2s infinite -webkit-animation:fade 2s infinite
-moz-animation:fade 2s infinite-o-animation:fade 2s infinite-ms-animation:fade 2s infinite
animation-fill-mode:both
}
@keyframes fade{
0%,100%{
opacity:0transform:scale(0)
}
50%{
opacity:1transform:scale(1)
}
}
</style>
</head>
<body>
<div class="open fade"> Test </div>
</body>
</html>