2016-09-23 37 views
1

當我創建了一個演示(不是的jsfiddle,不能讓它在設備工作):iOS的輸入欄滾動到頂部集中

http://i283951.iris.fhict.nl/test.html

當我打開這在我的iPad和滾動一路下來,然後單擊輸入,它一直滾動到頂部,然後顯示鍵盤。

我敢肯定,這也發生在iPhone上,在我的android我沒有這些問題。所以我認爲這與iO有關。

body { 
 
    margin: 0; 
 
    padding: 0; 
 
    height: 2000px; 
 
} 
 
.top { 
 
    width: 100%; 
 
    height: 50px; 
 
    position: fixed; 
 
    background-color: #AA3939; 
 
} 
 
.input-group { 
 
    margin-top: 12px; 
 
    margin-left: 50px; 
 
}
<html> 
 

 
<head> 
 

 
</head> 
 

 
<body> 
 
    <div class="top"> 
 
    <div class="input-group"> 
 
     <input type="search" placeholder="Search..."> 
 
     <button type="submit">Submit</button> 
 
    </div> 
 
    </div> 
 
</body> 
 

 
</html>

回答

0

我想你也許可以防止這種通過使用同樣喜歡這裏描述: https://stackoverflow.com/a/7771215/1501847

對於iOS Safari瀏覽器中運行你想要的東西像

網頁/ HTML應用程序
document.ontouchmove = function(event){ 
event.preventDefault(); 

}

+0

嗨thnx回覆,我應該在哪裏放置這段代碼?因爲當我把它放在頂部時,我再也不能滾動了(這可能是它的作用)。但我認爲我不能把它與重點結合起來。 –

+0

我認爲使用它幾乎是相同的,但使用jQuery:'jQuery('input-group.input')。bind('focusin focus',function(e){e.preventDefault(); })' – zero3nna

+0

'focusin focus'是否是一個錯字?因爲現在它不再做任何事情了。 –