Good day! I am new to programming. Please help make the floating menu ( http://echo.md ). When you scroll down the page, I want the header (where the menu and logo) are halved and attached to the top of the browser.
I tried everything, nothing comes out. I know that CSS is dirty / incorrect, I tried to attach at least something. :)
Thank you for your time!
HTML:
<div><script src="/js/floatingmenu.js" type="text/javascript"></script> <div id="header-one" class="default"> <div id="brand"> <div id="logo">Logo</div> <div id="logo2">Logo</div> </div> <div class="clear"></div> </div> </div>
Js:
$(document).ready(function () { var $menu = $("#header-one"); $(window).scroll(function () { if ($(this).scrollTop() > 50 && $menu.hasClass("default")) { $menu.removeClass("default").addClass("fixed"); $('#logo').fadeOut(0, function () { $('#logo2').fadeIn(); }); } else if ($(this).scrollTop() <= 50 && $menu.hasClass("fixed")) { $menu.removeClass("fixed").addClass("default"); $('#logo2').fadeOut(0, function () { $('#logo').fadeIn(); }); } }); });
CSS:
#brand { /* блок, который служит оберткой для логотипа и контактов */ float:left; width:30%; } #logo { font-size:28px; color:#fff; } #logo2 { display:none; /* блок контактов изначально скрыт и появится только при прокрутке */ font-size:12px; color:#fff; } #header-one { width: 920px; text-transform: uppercase; text-align: center; line-height: 50px; background: #69c; } #header-one ul { float:right; padding:0; margin:0; width:70%; } #header-one li { display: inline; list-style:none; margin: 5px 10px; } #header-one li a { padding:5px 10px; color:#fff; text-decoration: none; } #header-one li a:hover { background: #36c; color: #ff0; } #header-one.default { width:920px; } #header-one.fixed { position:fixed; top:0; left:0; width:100%; } .clear { clear: both; }