Home > Web Front-end > H5 Tutorial > body text

How can I implement a circular clickable area on the page?

PHP中文网
Release: 2017-06-21 14:33:57
Original
2384 people have browsed it

1. map+area

DW software implementation method Video:

2. border-radius (H5)

  1. <style>

  2. ## .circle{

  3. /*Circle Settings*/

  4. ## Width:100px;
  5. Height:100px;
  6. border-radius: 50%;
  7. cursor: pointer;
  8. /*Text settings*/
  9. position: absolute;
  10. left:50px;
  11. top:50px;
  12. -Height: 100px;
  13. ## Text-Align: Center;
  14. background-color:dimgray;

  15. }

  16. style
  17. >

#3. Pure js implementation

Simple algorithm to find whether a point is on a circle, obtain mouse coordinates, etc.

Distance calculation formula between two points


|AB|=Math.abs(Math.sqrt(Math.pow(X2-X1),2)+Math.pow(Y2-Y1,2))

Assume that the center of the circle is (100,100) and the radius is 50. Clicking inside the circle will pop up the corresponding information, and outside the circle, the information that is not within the circle will be displayed

document.onclick=
function(e){
    1. ##var r=50;//Round Radius

    2. ## var x1=100,y1=100,x2= e.clientX;y2= e.clientY;

    3. //Calculate the distance between the mouse point position and the center of the circle

    4. ##var len=Math.abs(Math.sqrt (Math.pow(x2-x1,2)+Math.pow(y2-y1,2)));

    5. ##if(len<=50) {
    6. ## console.log(

      "内")
    7. ## }else{

    8. ##                   console.log("外")                                                                                         down     ’     out out through out out through ’ s ’ through ’ through ’ through ’ through ’ through ‐ off ‐ ‐ ‐ n ‐ ,                           to ## }

The above is the detailed content of How can I implement a circular clickable area on the page?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!