Ich versuche Terminal scroll Verhalten zu simulieren, die sofort die Ansicht um 3 Zeilen verschieben, ohne glatte Scroll-Animation.Wie Scroll-Ereignis und Richtung in einem nicht scrollbaren Element mit Javascript zu erkennen?
Hier ist meine vereinfachte CSS und HTML-Struktur:
body {
overflow: hidden;
font-size: 13px;
line-height: 1.2em;
}
section {
width: 100%;
}
section#tabs {
position: fixed;
top: 0;
background-color: grey;
}
section#main {
margin: 15px 0;
}
section#controls {
position: fixed;
bottom: 0;
background-color: grey;
}
section#imgView {
position: fixed;
top: 100%;
background-color: red;
}
<html>
<body>
<article>
<div data-reactroot>
<section id="tabs">
<span>[abc]</span>
<span>[bcd]</span>
<span>[cde]</span>
<span>[def]</span>
<span>[efg]</span>
</section>
<section id="main">
<div>some texts that is long enough to make this snippet properly represent some shape I want to show</div>
<div>some texts that is long enough to make this snippet properly represent some shape I want to show</div>
<div>some texts that is long enough to make this snippet properly represent some shape I want to show</div>
<div>some texts that is long enough to make this snippet properly represent some shape I want to show</div>
<div>some texts that is long enough to make this snippet properly represent some shape I want to show</div>
<div>another texts to tell the difference on the height</div>
<div>another texts to tell the difference on the height</div>
<div>another texts to tell the difference on the height</div>
<div>another texts to tell the difference on the height</div>
<div>another texts to tell the difference on the height</div>
<div>another texts to tell the difference on the height</div>
<div>another texts to tell the difference on the height</div>
<div>another texts to tell the difference on the height</div>
<div>another texts to tell the difference on the height</div>
<div>another texts to tell the difference on the height</div>
<div>some texts that is long enough to make this snippet properly represent some shape I want to show</div>
<div>some texts that is long enough to make this snippet properly represent some shape I want to show</div>
<div>some texts that is long enough to make this snippet properly represent some shape I want to show</div>
<div>some texts that is long enough to make this snippet properly represent some shape I want to show</div>
<div>some texts that is long enough to make this snippet properly represent some shape I want to show</div>
<div>another texts to tell the difference on the height</div>
<div>another texts to tell the difference on the height</div>
<div>another texts to tell the difference on the height</div>
<div>another texts to tell the difference on the height</div>
<div>another texts to tell the difference on the height</div>
<div>another texts to tell the difference on the height</div>
<div>another texts to tell the difference on the height</div>
<div>another texts to tell the difference on the height</div>
<div>another texts to tell the difference on the height</div>
<div>another texts to tell the difference on the height</div>
</section>
<section id="controls">
<div>This will always be at the bottom.</div>
</section>
<section id="imgView">
<div>You're not supposed to see this sentence.</div>
</section>
</div>
</article>
</body>
</html>
Der Abschnitt tabs
und controls
wird im Browser an ihren jeweiligen Kanten kleben, und imgView
nicht, es sei denn etwas sichtbar sein code ruft es auf, indem es seine positionsbezogenen Eigenschaften ändert.
Ich machte es so Körper hat overflow: hidden;
, ich kann Methoden zum Vergleich der aktuellen Bildlaufposition mit vorherigen nicht verwenden.
Wie kann ich implementieren dies als 'window.scrollY' wird nicht in meinem Fall ändern? – Dinir
Ich habe die Antwort angepasst, ich hoffe, das hilft – Moritz