javascript - stop event and set variable to default -
following problem. have long scrolling page adds classes every div if in viewport inview.js
var $div1 = $('#div1'); var $div2 = $('#div2'); //..... var only_once = 0; $('#div1, #div2, #div3, #div4, #div5').bind('inview', function (event, visible) { if (visible == true) { $(this).addclass("inview"); } else { $(this).removeclass("inview"); } });
when adds class im doing events , if status should happen if inview fired first time , stops. tried with switching only_once 1.
if($div1.hasclass("inview")){ // here functions... if (only_once == 0) { $('.float-second').css('left', 0); $('.float-second').css('top', 0); only_once = 1; } if($div2.hasclass("inview")){ // here functions... if (only_once == 1) { $('.float-third').css('left', 0); $('.float-third').css('top', 0); only_once = 2; } // , other divs
the problem is, when way doesnt fire when site loads @ middle or bottom , im scrolling or downwards because of if status needs first events because of value before. hope point, how can work well?
i think understand problem having. can check how much page scrolled using:
$(document).scrolltop();
if it's greater value decide can phone call functions need phone call otherwise if loads @ top of page plugin you.
javascript jquery html
No comments:
Post a Comment