jquery - Disapear element when off screen -


i'm trying disapear element when of screen , appear new one. problem is, element disapear if it's not off screen on every scroll.

here code:

$(window).scroll(function () {     scrollhide('#zabiegi'); });  function scrollhide(sectionid) {     if ($(window).width() < 968) {         $(sectionid).each(function () {             if (($(sectionid).find('.two').offset().top - $(window).scrolltop()) < 20) {                 $(sectionid).find('.two').stop().fadeout( "slow", function() {                     $(sectionid).find('.one').fadein();                     updatemargin(sectionid,'.one');                 });             }          });     } } 

i've tryied different approach time - nothing happens , if statement give false.

$(window).scroll(function () {     scrollhide('#zabiegi'); });  function scrollhide(sectionid) {     if ($(window).width() < 968) {         $(sectionid).each(function () {              var off = $(sectionid).find('.two').offset();             var t = off.top;             var h = $(sectionid).find('.two').height();             var doch = $(window).height();             console.log(t > 0 && t + h < doch);              if (t > 0 && t + h < doch) {                 $(sectionid).find('.two').stop().fadeout( "slow", function() {                     $(sectionid).find('.one').fadein();                     updatemargin(sectionid,'.one');                 });             }          });     } } 

ok, i've found solution. problem in conditional statement if. here code:

function scrollhide(sectionid) {     if ($(window).width() < 968) {         $(sectionid).each(function () {             if (($(sectionid).find('.two').offset().top + $(sectionid).find('.two').outerheight() - $(window).scrolltop()) < 0  ) {                 $(sectionid).find('.two').stop().fadeout( "slow", function() {                     $(sectionid).find('.one').fadein();                     updatemargin(sectionid,'.one');                 });             }          });     } }); 

but still got problem... above script works when scroll down not ... i've added conditional statement:

if (($(sectionid).find('.two').offset().top + $(sectionid).find('.two').outerheight() - $(window).scrolltop()) < 0 || ($(sectionid).find('.two').offset().top - $(sectionid).find('.two').outerheight() + $(window).scrolltop()) < 0 ) { 

and in console.log output ok - shows 0 when above element, still not working...


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -