-2
<!DOCTYPE html>
<html>
<head>
<style>
#banner {
position: fixed;
left: 10px;
height: 300px;
width: 110px;
padding: 10px 5px;
text-align: center;
background-color: #fff;
border: 5px solid #000;
}
#footer { height: 600px; background: #888; }
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script>
function checarScroll() {
var margem = 10;
var posicao = $(document).scrollTop() + window.innerHeight;
var footertop = $('#footer').offset().top;
var meiodapagina = window.innerHeight / 2;
var maximo = footertop + meiodapagina - margem;
if (posicao < maximo) {
$('#banner').css('bottom', meiodapagina + 'px');
} else {
$('#banner').css('bottom', (margem + (posicao - footertop)) + 'px');
}
}
$(document).ready(checarScroll);
$(document).scroll(checarScroll);
</script>
</head>
<body>
<div style="height:1200px">
Conteúdo da página
</div>
<div id="banner">
<div class="bannerconteudo">BANNER</div>
</div>
<div id="footer">Aqui está o footer</div>
</body>
</html>
But only the
header
in your code? In your question you can’t see where or how you are using yourheader
... I don’t think you need JS or jQuery for that, with CSS and position:Ticky you solve!– hugocsl