javascript - Moving image while scroll down and up on path -
i design ball (images) on website when scrolling down or up, ball gonna stick on path while scrolling.
screenshot:
but don't know how stick ball on path.
i tried
if (s > 40 && s <= 60) { if(scrollposition == 0){ position += 2; } if(scrollposition == 1){ position -= 2; } } else if (s > 60 && s <= 80) { if(scrollposition == 0){ position -= 2; } if(scrollposition == 1){ position += 2; }
but weird.. here code https://codepen.io/ookangzheng/pen/eeyqjj?editors=0011
thanks
i have tried few way solve problem. first of all, think hard use s element in coding guide frequency of increase position because seen different every scrolling.
my suggestion here. try use whole height , window height calculate percentage , use it. also, not going use point changing position because scrolling duration large. not necessary point small.
fyi, have added transition-duration: 1s;
, transition-property: all;
in css made smooth movement.
percentage coding
var s = $(this).scrolltop(); d = $(document).height(), c = $(this).height(); var length = d - c; var pctscrolled = math.floor(s / length * 100) ;
calculate position
if( s < 33){ position = 60; } if(s > 33 && s < 66){ position = 40; } if(s > 66 && s < 100){ position = 60; } if(s == 100 || s == 0 ){ //initial position on top , bottom position = 50; }
hope find way!
Comments
Post a Comment