scroll 滾動到指定位置觸發事件 and 點擊一按鈕/鏈接讓頁面定位在指定的位置


scroll 滾動到指定位置觸發事件:
$(function(){
$(window).scroll(function() {
var s =$(window).scrollTop();
if (s>=782) {//782是導航條離頁面頂部的距離(px)
$('.nav').addClass('fixednav');
}
else{
$('.nav').removeClass('fixednav');
}
});
});
.fixednav{
position:fixed;
top:0px;
left:0px;
width:100%;
z-index:100000;
_position:absolute;
_top:expression(eval(document.documentElement.scrollTop));
}

點擊一按鈕/鏈接讓頁面定位在指定的位置:
<div class="nav">
<a href="#aaa">導航1</a>
<a href="#bbb">導航2</a>
<a href="#ccc">導航3</a>
<a href="#ddd">導航4</a>
</div>


通過錨點實現
<a name="aaa" id="aaa"></a>
<a name="bbb" id="bbb"></a>
<a name="ccc" id="ccc"></a>
<a name="ddd" id="ddd"></a>

鼠標滾動到底部事件:
$(window).scroll(function() {
if ($(document).scrollTop() + $(window).height() >= $(document).height()) {
$(".foot").css('opacity','1');
} else {
$(".foot").css('opacity','.3');
}
});
 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM