jQuery cannot compare offset result with int/string -
so portfolio under development need work offset coords of specific div. div getting offset of has got position fixed , starts top:150px.
so want console.log ayy when offset between 150 , 550. problem returns ayy though surpasses 550. tried without parseint , both ways don't work.
this code:
$(window).scroll(function() { var currentoffset = $('#offset').offset().top; currentoffset = parseint(currentoffset); console.log(currentoffset); if(($(currentoffset) >= '150') && ($(currentoffset <= '550'))) { console.log('ayy'); } else { console.log('nay'); } }); this console logs console log
any appreciated.
offset().top returns int parseint() redundant , creating jquery object when using $(currentoffset) use directly currentoffset.
use
$(window).scroll(function() { var currentoffset = $('#offset').offset().top; if (currentoffset >= 150 && currentoffset <= 550) { console.log('ayy'); } else { console.log('nay'); } }); note: not using () properly.
Comments
Post a Comment