jquery - Change the fill of an svg as a progress bar passes in the background -



jquery - Change the fill of an svg as a progress bar passes in the background -

i have progress bar drops in when user scrolls downwards more 100 pixels. background of progress bar fills red. progress bar container contains svg of tree white.

how can alter fill color of svg progress bar passes behind it. so, if progress bar halfway through of tree, left half white , right half still red. possible? using jquery currently.

i mocked quick pen here: http://codepen.io/redbranchmedia/pen/agfme

here script using progress bar:

// fills progress bar on scrolldown jquery(document).on('ready', function() { var winheight = $(window).height(), docheight = $(document).height(), progressbar = $('progress'), max, value; /* set max scrollable area */ max = docheight - winheight; progressbar.attr('max', max); jquery(document).on('scroll', function(){ value = $(window).scrolltop(); progressbar.attr('value', value); }); }); // end progress bar

you're there. animation trick utilize reddish tree behind white tree. when white tree unmasked, reddish tree appears.

earlier revision answers question, isn't 100% pixel accurate various window width , window zoom (may possible prepare more math). hence new update below.

update: new codepen illustration using gradient gradually turn white. adjust value 0.1 in (max*0.1) if want turn white later

jquery svg fill

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -