我使用js來支持Web項目上的滾動。 它工作得很好,除了微軟的邊緣。在ms邊上的javascript同步滾動
在邊緣它首先滾動頁面的內容和一個位後,它執行從我的js滾動。我沒有在滾動功能上使用preventDefault,因爲我不用我的js滾動整個內容。
予製備的JSFiddle其示出了該問題。 我也發現這個問題Lag in scrolling behavior on IE 10 and IE Edge modes它有同樣的問題,但沒有得到答案。這個問題的作者寫了這個JSFiddle作爲例子,這導致了我嘗試它的同樣的問題。
這裏也是我上的jsfiddle製備的樣品:
if($(window).width() >= 300) {
\t \t // scroll function
$(window).scroll(function (e) {
\t \t setDefaultOffsets();
//e.preventDefault();
//e.stopPropagation();
//e.returnValue = false;
var offset = $(window).scrollTop();
localStorage.setItem('scrollTop', offset);
$("#teaser").css({top: (TeaseDefaultTop - offset) + 'px'});
if ((PreOffset - offset) <= SwitchPos) {
$('#controlbar').css({top: SwitchPos + 'px'});
} else {
$('#controlbar').css({top: (PreOffset - offset) + 'px'});
}
return false;
});
$(function() {
\t \t setDefaultOffsets();
var previousOffset = localStorage.getItem('scrollTop');
if (previousOffset > maxScrollOffset) {
previousOffset = maxScrollOffset;
}
if (previousOffset > 100) {
window.scroll(0, previousOffset);
} else {
setTimeout(function() {
if ($(window).scrollTop() == 0) {
$('html, body').animate({
scrollTop: $('#teaser').offset().top
}, 1000);
}
}, 500);
}
});
$(window).scrollTop(0.5)
}
function setDefaultOffsets() {
\t // difderent values for the different media querys
\t if($(window).width() > 0) {
\t \t maxScrollOffset = 100;
\t \t TeaseDefaultTop = 101;
\t \t PreOffset = 300;
\t \t SwitchPos = 101;
\t }
}
html, body {
min-width: 100%;
min-height: 500%;
}
#header {
width: 100%;
height: 100px;
background-color: lightblue;
position: fixed;
top:0px;
left: 0px;
z-index: 7;
}
#teaser {
color: transparent;
height: 200px;
width: 100%;
background-image: url(http://i.imgur.com/NwOWE.jpg);
background-position: 0px 0px;
background-repeat: repeat;
background-size: auto 200px;
position: fixed;
top: 101px;
left: 0px;
z-index: 3;
}
#controlbar {
height: 50px;
width: 100%;
background-color: lightgreen;
position: fixed;
top: 252px;
left: 0px;
z-index: 5;
}
#content {
margin-top: 350px;
}
#slogan {
cursor: pointer;
background-color: rgba(220, 140, 40, 0.6);
width: auto;
display: inline-block;
position: absolute;
z-index: 4;
left: 10%;
padding: 10px;
top:200px;
}
#demo1 {
cursor: pointer;
background-color: rgba(40, 140, 220, 0.8);
width: auto;
display: inline-block;
position: absolute;
z-index: 6;
right: 10%;
padding: 10px;
top:300px;
}
#demo2 {
cursor: pointer;
background-color: rgba(140, 220, 40, 0.8);
width: auto;
display: inline-block;
position: absolute;
z-index: 6;
right: 10%;
padding: 10px;
top:200px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> </script>
<div id='header'>
Header with Menue, Logo and stuff
</div>
<div id='teaser'>
Teaser Image
</div>
<div id='slogan'>
A slogan or something else (just 3-10 words).
</div>
<div id='demo1'>
For demonstartion
</div>
<div id='demo2'>
For demonstartion
</div>
<div id='controlbar'>
Some Elements like Print, PDF Buttons, search form, breadcrumbs ....
</div>
<div id='content'>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.
</div>
// Source of image and a bit of the code:
// https://jsfiddle.net/0z8mvewo/
是否有人知道這個問題的變通方法/解決方案?
編輯: 這真的很奇怪,我找不到更多的資料關於這個問題的任何地方。這個問題是否只發生在虛擬機上? 我是一名mac用戶,我在Microsoft Edge上的測試是在VMWare Fusion上託管的虛擬機上完成的。 我測試了在macbook pro觸摸板和普通的Logitech鼠標上的滾動。
謝謝你的清晰答案。 我已經看到,從我上一篇文章中的snippin不能在stackoverflow上工作,但在JSFiddle頁面上它適用於我。你對透明區域的想法是相當不錯的,但遺憾的是,我有這方面的內容需要點擊。 正如我所看到的,這個問題沒有更多的解決方法。我必須過度使用我使用的div設置,並創建一個解決方案,我不用js進行滾動,反之亦然。用js滾動一切(我開始討厭邊:()。 – FuFu