css - change div color after scrolling 15% down with jquery -


i have jquery code below makes div scroll. change div color #32200f when down 15% top.then return original barckground when less 15% top.

<script type="text/javascript">         $().ready(function() {                 var $scrollingdiv = $("#navbar");                  $(window).scroll(function(){                                     $scrollingdiv                                 .stop()                                 .animate({"margintop": ($(window).scrolltop() + 0) + "px"}, "slow" );                 });         }); </script> 

here css code of original background.i can make class make easier:

#navbar {      /* fallback web browsers don't support rgba */      background-color: rgb(0, 0, 0);      background-color: rgba(50,32,15,0.5);           /* ie 5.5 - 7*/      filter:progid:dximagetransform.microsoft.gradient(startcolorstr=#4c32200f, endcolorstr=#4f32200f);      /* ie 8*/      -ms-filter: "progid:dximagetransform.microsoft.gradient(startcolorstr=#4c32200f, endcolorstr=#4f32200f)"; } 

try:

$(document).ready(function () {    var $scrollingdiv = $("#navbar");     $(window).scroll(function () {        $scrollingdiv.stop()            .animate({            "margintop": ($(window).scrolltop() + 0) + "px"        }, "slow");        $scrollingdiv.css("background-color", (($(window).scrolltop() / $(document).height()) > 0.15) ? "orange" : "");      }); }); 

demo


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -