My ultimate goal is to get my header to switch from a position of relative to fixed when the window gets to a certain point. In trying to get there I came up with this function which doesn't give my any errors but also dosen't appear to do anything. Could someone help me understand why? It's the last script loaded on the page and jquery is called before it..
<script type="text/javascript">
$(function() {
var $window = $(window);
function top() {
var $top = $window.scrollTop();
if( $top > 100 ) {
$("header").css("position","absolute");
}
else {
$("header").css("position","fixed");
}
};
});
</script>
What if i wanted to limit it to mobil applications? shouldn't something like this work...
<script type="text/javascript">
$(function() {
var $window = $(window).width();
function windowWidth() {
if ( $window < 480 ) {
function top() {
var $top = $window.scrollTop();
if( $top > 100 ) {
$("header").css("position","absolute");
}
else {
$("header").css("position","fixed");
}
};
$(window).scroll(top);
}
};
});
</script>