Sayfa aşağı kaysada üstte sabit kalan menü yapmak için aşağıdaki hazır kodları kullanabilirsiniz. Html kodlarını sayfanızda menüyü görmek istediğiniz yere kopyalayın ve kendinize göre düzenleyin. Ayrıca bu kodlar içinde yer alan gereksiz bölümleri çıkarabilirsiniz.
Html Kodları;
Kod:
<div id="unstickyheader"> <p>This is some text that comes before our <strong>Sticky Header</strong></p> <p>This is some text that comes before our <strong>Sticky Header</strong></p> <p>This is some text that comes before our <strong>Sticky Header</strong></p> </div> <div id="stickyheader"> <table width="100%"> <tr> <td>Sticky Text 1</td> <td>Sticky Text 2</td> <td>Sticky Text 3</td> <td>Sticky Text 4</td> <td>Sticky Text 5</td> </tr> </table> </div> <div id="stickyalias"></div> <div id="othercontent"> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
JS Kodları;
Kod:
$(function(){ // Check the initial Poistion of the Sticky Header var stickyHeaderTop = $('#stickyheader').offset().top; $(window).scroll(function(){ if( $(window).scrollTop() > stickyHeaderTop ) { $('#stickyheader').css({position: 'fixed', top: '0px'}); $('#stickyalias').css('display', 'block'); } else { $('#stickyheader').css({position: 'static', top: '0px'}); $('#stickyalias').css('display', 'none'); } }); });
CSS kodları:
Kod:
table { background: black; color: white;} body, td { font: 13px sans-serif; } #stickyheader { width: 100%; height: 10px; } #stickyalias { display: none; height: 10px; } #unstickyheader { margin-bottom: 15px; } #othercontent { margin-top: 20px; }