面试题分享(1)
如图:实现点击圆形区域提示是圆形,点击正方形区域提示是正方形,点击三角形提示是三角形。

我的实现:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> .circle { width: 200px; height: 200px; border-radius: 50%; background: green; margin: 0 auto; overflow: hidden; } .square { width: 141px; height: 141px; background: yellow; margin: 0 auto; margin-top: 30px; } .triangle { width: 141px; height: 141px; background: red; clip-path: polygon(50% 0, 0 100%, 100% 100%); margin: 0 auto; } </style> </head> <body> <div class="out"> <div class="circle"> <div class="square"> <div class="triangle"> </div> </div> </div> </div> </body> <script src="https://cdn.bootcss.com/jquery/1.11.1/jquery.js"></script> <script> $('.circle').click(function () { alert('这是圆'); event.stopPropagation(); }); $('.square').click(function () { alert('这是正方形'); event.stopPropagation(); }); $('.triangle').click(function () { alert('这是三角形'); event.stopPropagation(); }) </script> </html>
主要是用了css3的clip-path属性,欢迎留下你的想法。

浙公网安备 33010602011771号