美文网首页
深入了解点击事件传播过程

深入了解点击事件传播过程

作者: 飞天小猪_pig | 来源:发表于2019-09-24 22:33 被阅读0次
HTML:
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div class="red">
<div class="blue">
  <div class="green">
    <div class="yellow">
      <div class="orange">
        <div class="purple">
        </div>
      </div>
    </div>
  </div>
</div>
</div>
</body>
</html>
CSS:
*{margin:0;padding:0;box-sizing:border-box}
.red.active{
background:red;
}
.blue.active{
background:blue;
}
.green.active{
background:green;
}
 .yellow.active{
background:yellow;
}
.orange.active{
background:orange;
}
.purple.active{
background:purple;
}  
div{
border:1px solid black;
padding:10px;
transition:all 1s;
display:flex;
flex:1;
border-radius:50%
}
.red{
width:100vw;
height:100vw;
}
JS:
var n=1
$('div').on('click',function(e){
setTimeout(function(){
$(e.currentTarget).addClass('active')
},n*500)
n+=1
})
效果图:
2019-09-24_221940.png

相关文章

网友评论

      本文标题:深入了解点击事件传播过程

      本文链接:https://www.haomeiwen.com/subject/ennbuctx.html