我試圖建立一個窗口位於屏幕中心,當我向下滾動它將永遠在中心,我試過以下代碼:移動滾動條時總是保持窗口在中心
<style>
#Window {
display: none;
text-align: center;
border: 1px solid #333;
position:absolute;
width: 200px;
height: 80px;
z-index:9999;
background:#fff;
border-radius: 5px;
padding: 10px;
}
</style>
<script>
$("#window").css('top', 200);
$("#window").css('left', winW/2- $("#window").width());
$(window).scroll(function() {
var winH = $(window).height();
setTimeout(function(){
$('#alertWindow').animate({'top':winH/2-$("#window").height()/2},200);
}, 1000);
});
</script>
<div id="window">this is scroll window</div>
的問題是,當我向下滾動,窗口移動到中心在第一時間它的作品,但是當我再次滾動,它會保持不動的中心,我覺得滾動功能只調用一次,當我向下滾動或向上滾動時,如何保持窗口不斷移動到屏幕的中心,任何人都可以幫助我,如果我提供了整個代碼,很抱歉。
這是很好的解決方案,但你能解決它基於jquery,謝謝! – smith
謝謝。也幫助了我。 +1 – Pankaj