javascript - Changing bootstrap navbar scroll effects -
i making bootstrap navbar on scroll change background color red jquery , not work please.
html code
<header class="navbar navbar-default navbar-fixed-top" style="background-color:transparent; border-color:#e74c3c;"> <div class="navbar-brand" style="color:white;">podlle</div> <div class="nabar-item"> <a style="color:white;" href="#"<div class="navbar-text">sign up</div></a> <a style="color:white;" href="#"<div class="navbar-text">log in</div></a> </div> jquery code
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.js"> $(document).scroll(function(){ $(".navbar").css("background-color" , "red"); }) please , thanks
you need wait document exist (dom ready) , whatever it. jquery, can using shortcut $(callbackfuncion).
the following example code i've wrote print console when page scrolls , update element class nav-bar have red background:
$(function () { // wait domready $(document).on('scroll', function () { console.log("scrolling."); $('.nav-bar').css('background-color', 'red'); }); }); this full sample code working: http://jsfiddle.net/xa8doyb4/
Comments
Post a Comment