我有一个Bootstrap网站,其中包含< select>元素内部模态.
我的问题是,在iOS(尝试在iPhone 5)当我尝试打开选择选择一个选项背景内容(模态后)自动滚动到页面的顶部.
我在Safari和Google搜索中收到此错误,而Chrome和Mercury browser上没有错误.
有人知道这个问题的原因和解决方法吗?谢谢
解决方法
我有同样的问题,找到解决方案,真正解决了这个问题:
if( navigator.userAgent.match(/iPhone|iPad|iPod/i) ) {
$('.modal').on('show.bs.modal',function() {
// Position modal absolute and bump it down to the scrollPosition
$(this)
.css({
position: 'absolute',marginTop: $(window).scrollTop() + 'px',bottom: 'auto'
});
// Position backdrop absolute and make it span the entire page
//
// Also dirty,but we need to tap into the backdrop after Boostrap
// positions it but before transitions finish.
//
setTimeout( function() {
$('.modal-backdrop').css({
position: 'absolute',top: 0,left: 0,width: '100%',height: Math.max(
document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight
) + 'px'
});
},0);
});
}
希望对有同样问题的人有帮助.