如何在頁面上實現一個圓形可點擊區域


1.   map+area

DW軟件實現方法    視頻:http://www.chuanke.com/3885380-190205.html

2.  border-radius(H5)

  1. <style>  
  2.  .circle{  
  3. /*圓設置*/
  4.      width:100px;  
  5.      height:100px;   
  6.      border-radius: 50%;  
  7.      cursor: pointer; 
  8.  /*文字設置*/
  9.      position: absolute;  
  10.      left:50px;  
  11.      top:50px;    
  12.      line-height: 100px;  
  13.      text-align: center;  
  14.      color: white;  
  15.      background-color:dimgray; 
  16.  }  
  17. </style

3. 純js實現

求點在不在圓上的簡單算法、獲取鼠標坐標等等
兩點之間的距離計算公式

 

 

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

 

假設圓心為(100,100),半徑為50,在圓內點擊彈出相應的信息,在圓外顯示不在圓內的信息

    1. document.onclick=function(e){  
    2.     var r=50;//圓的半徑  
    3.     var x1=100,y1=100,x2= e.clientX;y2= e.clientY;  
    4. //計算鼠標點的位置與圓心的距離  
    5.     var len=Math.abs(Math.sqrt(Math.pow(x2-x1,2)+Math.pow(y2-y1,2)));  
    6.     if(len<=50){  
    7.         console.log("內")  
    8.     }else{  
    9.         console.log("外")  
    10.     }  
    11.  }  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM