I'm having trouble setting two positions in a scroll function using offset.
I created a fiddle so you can see ... http://jsfiddle.net/motocomdigital/SGCHt/12/
When you open this script, reduce the script viewport to the same size as the screenshot below.
MY PROBLEM
You can see that I use conditional operators to control the positioning of the blue tabs, depending on where they scroll to.
The yellow columns are tab containers, and I use the if else
command to control the bottom position, so the blue tabs never go beyond the yellow containers.
But I can't get this to work. My lower positional offset does not work.
var $tab = $('.tab-button'); $(window).bind("resize.browsersize", function() { var windowHalf = $(window).height() / 2, content = $("#content"), pos = content.offset(); $(window).scroll(function(){ if ($(window).scrollTop() >= pos.top + windowHalf ){ $tab.removeAttr('style').css({ position:'fixed', top:'50%'}); } else if ($(window).scrollTop() >= pos.bottom + windowHalf ){ $tab.removeAttr('style').css({ position:'absolute', bottom:'0px'}); } else { $tab.removeAttr('style').css({ top: $(window).height() + 'px' }); } }); }).trigger("resize.browsersize");
Can someone help me figure out where I am going wrong.
Thanks josh
Joshc source share