Ich habe eine feste Kopfzeile am oberen Rand der Seite, und nach dem Scrollen nach unten und zeigt einen Schieberegler, ich habe eine zweite Anker-Menü. Wie kann ich dieses Ankermenü klebrig zum Header machen. Zweites Menü sticky to header
Antwort
Ich bin mir ziemlich sicher, dass das ist, was Sie suchen!
https://codepen.io/will0220/pen/QqreKY
Grundsätzlich müssen Sie die Mitte Inhalt Navigationsleiste die Position vom oberen Rand des Bildschirms prüfen, die durch die Überprüfung des Elements Top-Offset minus der Scroll-Fenster erfolgt. Wenn Sie nach oben oder unten scrollen, binden Sie sich ein. Wenn Sie also nach unten scrollen und das Mid-Page-Nav weniger als die Höhe Ihrer festen Kopfzeile vom oberen Bildschirmrand entfernt ist, klonen Sie es und fügen Sie eine feste Version hinzu. Klonen ist der Weg, also ändert sich die Länge des Inhalts nicht. Wenn wir dann in die entgegengesetzte Richtung scrollen, können wir einfach überprüfen, wo das ursprüngliche In-Page-Nav (das noch existiert), mit der gleichen Berechnung wie zuvor.
Das in der festen Navigationsleiste Schalt behandeln werden:
var thisScroll = 0, lastScroll = 0;
$(window).scroll(function(){
thisScroll = $(window).scrollTop();
if($('nav').offset().top - thisScroll <= 50 && !$('#stuckNav').length && thisScroll > lastScroll){
var newNav = $('nav').clone();
newNav.attr('id', 'stuckNav');
$('#wrapper').append(newNav);
}
else if($('nav').offset().top - $(window).scrollTop() > 50 && thisScroll < lastScroll){
$('#stuckNav').remove();
}
lastScroll = thisScroll;
});
Und die CSS braucht etwas wie folgt aus:
#stuckNav{
position: fixed;
top: 50px;
z-index: 2;
}
nav{
position: relative;
width: 100%;
background: #FFF;
text-align: center;
padding: 10px 0;
}
Das ist perfekt – rinkaslb
Mit nur javascript: https://codepen.io/claytron5000/pen/OxZKxB?editors=1010
var secondary = document.querySelector(".secondary");
var fromTop = secondary.offsetTop;
document.onscroll = function() {
if (!secondary.classList.contains("stuck") && window.pageYOffset >= fromTop) {
secondary.classList.add("stuck");
}
else if (secondary.classList.contains("stuck") && window.pageYOffset < fromTop){
secondary.classList.remove("stuck");
}
};
.container p {
max-width: 768px;
margin: auto;
}
.header, .secondary {
background: beige;
position: relative;
}
ul li {
display: inline-block;
background: lightgrey;
}
.stuck {
position: fixed;
top:0;
width: 100%;
}
<div id="container">
<div class="header">
<ul>
<li>here's</li>
<li>some</li>
<li>items</li>
</ul>
</div>
<p>Some content that will scroll away.</p>
<div class="secondary">
<ul>
<li>here's</li>
<li>different</li>
<li>items</li>
</ul>
</div>
<p>And a whole lotta ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
Where does it come from?
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>
</div>
- 1. Mehrere Sticky Header und Sidebars
- 2. Ionic 2 - Sticky-Header
- 3. Sticky scroll nav Menü
- 4. Sticky Header mit jquery
- 5. Auf Scroll Sticky Header
- 6. Storefront sticky header
- 7. Sticky Header mit recylerview
- 8. Scrollen sticky header jumping
- 9. zweites Dropdown-Menü nicht ausgewählt
- 10. UICollectionView mit einem sticky header
- 11. Sticky Top-Menü in Prestashop
- 12. CSS Jquery Scroll Sticky Menü
- 13. Sticky fixed top menü, wenn wir scrollen
- 14. UICollectionViewCell geht über sticky header
- 15. Sticky-Header in reaktiv-virtualisiert
- 16. Sticky-Header folgende dynamische Position
- 17. jquery sticky header with resize
- 18. Sticky Header mit Scroll-Hintergrund
- 19. Fixing JS Sticky Header Glitch
- 20. nicht geöffnet zweites Menü des Akkordeon Menüs
- 21. Responsive Sticky-Menü funktioniert nicht nach Scroll
- 22. reactjs read-sticky für fixed/sticky header funktioniert nicht
- 23. Sticky Header in Akkordeon-ähnlicher Anzeige
- 24. Responsive Menü wird nicht richtig sticky
- 25. Mein Problem ist Sticky-Menü auf Bildlauf
- 26. css Übergang bei Sticky-Menü funktioniert nicht
- 27. Making Drop-Down-Menü sticky mit PHP
- 28. Listening to Menü öffnen
- 29. Mache Header in einer scrollbaren Sidebar Sticky
- 30. Wie man einen sticky header schaltet?
Können Sie jQuery verwenden? – will
Haben Sie versucht, [header {position: sticky}] (https://developer.mozilla.org/en-US/docs/Web/CSS/position#CSS_4) zu verwenden? – styfle
Ja, ich kann Jquery verwenden. Ich benutze nie Position sticky – rinkaslb