javascript - jquery width increase/decrease with scroll -


i want increase , decrease width of div when scroll page . able increase width of div right after scroll down 150px , div width not decreasing when scroll before 50px coded .

code increase

var scroll_pos = 0; jquery(document).scroll(function() {     scroll_pos = $(this).scrolltop();     if (scroll_pos > 100) {         scroll_pos = 100;      }        jquery(".roadway-sec-1").animate({         width : (0+1*scroll_pos)+"%"     });            });  

code decrease

jquery(document).scroll(function() {     var current=jquery(".roadway-sec-1").width();     scroll_pos = $(this).scrolltop();     if (scroll_pos < 50) {         scroll_pos = 50;      }        jquery(".roadway-sec-1").animate({        width : "-=50"+"%"     });            });      

why don't trick in 1 function?

jquery(document).scroll(function() {     scroll_pos = $(this).scrolltop();     if (scroll_pos < 100 && scroll_pos > 50) {         jquery(".roadway-sec-1").animate({             width : scroll_pos+"%"         });     }    });  

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -