2016-10-23 114 views
0

我有以下片段。我沒有編寫任何腳本,它是純Css,但是當點擊標題時會觸發一些奇怪的事件。如果您單擊向下滾動並單擊標題,div容器將自動向上滾動。這是我想禁用它的不需要的事件。有人可以解釋爲什麼嗎?以及如何禁用它?爲什麼純Css監聽點擊事件並觸發滾動事件?

<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
     <style> 
 
     table, th, td { 
 
     border: 1px solid black; 
 
     } 
 
     table { 
 
     width: 100%; 
 
     table-layout: fixed; 
 
     background-color: green; 
 
     color: white; 
 
     } 
 
     .container { 
 
     height: 100px; 
 
     overflow-x:hidden; 
 
     overflow-y: auto; 
 
     border: none; 
 
     } 
 
     .section { 
 
     position: relative; 
 
     padding-top: 25px; 
 
     background-color: red; 
 
     } 
 
     th { 
 
     height: 0; 
 
     line-height: 0; 
 
     padding-top: 0; 
 
     padding-bottom: 0; 
 
     color: rgba(0, 0, 0, 0); 
 
     border: none; 
 
     white-space: nowrap; 
 
     } 
 
     .header { 
 
     broder: solid 1px black; 
 
     position: absolute; 
 
     color: black; 
 
     top:10px; 
 
     } 
 
     </style> 
 
    </head> 
 
    <body> 
 
     <div class="section"> 
 
     <div class="container"> 
 
      <table> 
 
       <col width="130"> 
 
       <col width="80"> 
 
       <tr> 
 
        <th> 
 
        Month 
 
        <div class="header">Month</div> 
 
        </th> 
 
        <th> 
 
        Savings 
 
        <div class="header">Savings</div> 
 
        </th> 
 
       </tr> 
 
       <tr> 
 
        <td>January</td> 
 
        <td>$100</td> 
 
       </tr> 
 
       <tr> 
 
        <td>February</td> 
 
        <td>$80</td> 
 
       </tr> 
 
       <tr> 
 
        <td>January</td> 
 
        <td>$100</td> 
 
       </tr> 
 
       <tr> 
 
        <td>February</td> 
 
        <td>$80</td> 
 
       </tr> 
 
       <tr> 
 
        <td>January</td> 
 
        <td>$100</td> 
 
       </tr> 
 
       <tr> 
 
        <td>February</td> 
 
        <td>$80</td> 
 
       </tr> 
 
       <tr> 
 
        <td>January</td> 
 
        <td>$100</td> 
 
       </tr> 
 
       <tr> 
 
        <td>February</td> 
 
        <td>$80</td> 
 
       </tr> 
 
       <tr> 
 
        <td>January</td> 
 
        <td>$100</td> 
 
       </tr> 
 
       <tr> 
 
        <td>February</td> 
 
        <td>$80</td> 
 
       </tr> 
 
      </table> 
 
     </div> 
 
     </div> 
 
     <p>The col width attribute is not supported in HTML5.</p> 
 
    </body> 
 
</html>

回答

0

它不觸發點擊,當它被點擊標題和鼠標移動,造成滾動。剛上header級傷殘pointer-eventshttps://jsfiddle.net/8LcLvh93/1/

.header { 
    broder: solid 1px black; 
    position: absolute; 
    color: black; 
    top: 10px; 
    pointer-events: none; 
} 
+0

快到了,是否有可能禁用指針事件對於滾動只是因爲我想以後我的JavaScript中使用這個元素 – TSR