New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[html] 第18天 怎样在页面上实现一个圆形的可点击区域? #58
Comments
1、用canvas画布,弧线画圆,在canvas上监听点击事件 |
这个问题也可以理解为做一个圆。方案为两种,真的圆和模拟圆
|
|
总结了一下前面老哥们的回答
|
最简单的是border-radius: 50% |
|
总结了一下前面老哥们的回答 DOM 元素配合 border-radius: 50% 即可实现圆形点击区域。例子 利用 和 标签设置圆形点击区域。参考文章:HTML 标签及在实际开发中的应用 利用 SVG 作出圆形,然后添加点击事件。 如果在 canvas 上,就需要画出圆形,然后计算鼠标的坐标是否落在圆内。 |
<style> #app{ width: 0; height: 0; border: 100px solid blue; border-radius: 50%; } </style> <script> function test(){ console.log('点到了圆') } </script> |
border-radius: 50%div {
overflow: hidden;
width: 50px;
height: 50px;
background: red;
border-radius: 50%;
} map + area<img src="test1.jpg" alt="test" usemap="#test">
<map id="test" name="test">
<area shape="rect" coords="20,20,80,80" href="#rect" alt="矩形">
<area shape="circle" coords="200,50,50" href="#circle" alt="圆形">
<area shape="poly" coords="150,100,200,120,180,130,190,180,150,150,100,160,140,120,100,110" href="#poly" alt="多边形">
</map> canvas// 用canvas画布,弧线画圆,在canvas上监听点击事件
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.arc(100,75,50,0,2*Math.PI);
ctx.stroke(); SVG<!-- 利用 SVG 作出圆形,然后添加点击事件 -->
<svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg">
<circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red" onclick="alert(3)"/>
</svg> |
|
div添加border-radius: 50%;添加click事件 |
第18天 怎样在页面上实现一个圆形的可点击区域?
The text was updated successfully, but these errors were encountered: