2013-09-30 29 views
3

我正在嘗試禁用導航滑動。 我不希望網頁在用戶向左或向右滑動時返回或前進。禁用導航在Metro IE中滑動

我注意到我們可以在html元素上設置觸摸動作爲無,以防止行爲。 但是,當滾動某個溢出的子元素時,它會「鏈接」滾動,然後允許後退導航。

所以我想在html元素上添加-ms-scroll-chaining:none,但它只有在元素滾動時才起作用。 因此,添加溢出:在html上滾動實際上是訣竅。但現在我的滾動條顯示在其他瀏覽器上。

這樣做的正確方法是什麼?

html { 
     -ms-touch-action: none; /* Doesn't work if scrolling from child element */ 
     -ms-scroll-chaining: none; /* Works only with the next line */ 
     overflow: scroll; /* With this line all the other browsers have a scrollbar */ 
    } 
+1

這不是一個好主意,採取人民的瀏覽器控制和嘗試,並禁用特定的功能。尤其像導航和歷史。但我可以告訴你,你可以在javascript中查看HTML5的歷史API並檢測導航事件。 – CP510

回答

4

我用這個:

@media screen and (-ms-high-contrast: none) { 
    // Windows 8+ IE only 
    html { 
     overflow-x: scroll; 
     -ms-touch-action: none; 
     -ms-overflow-style: none; 
     -ms-scroll-chaining: none; 
    } 
} 
0

你試過

body, html { 
    -ms-touch-action:none; 
} 

,併爲每一個可滾動類(Y - 軸)申請

-ms-scroll-chaining: none;

在我的項目,我們有特殊的類滾動什麼很舒服:

.scroll-y { 
    overflow-y: auto; 
    overflow-x: hidden; 
    -ms-scroll-chaining: none; 
} 

爲我工作

+0

這太約束了。我仍然想要-ms-scroll-chaining來處理我的元素。鏈接在網站上很好,很重要。 – jsgoupil