location.hash 屬性:設置或取得當前URL中的錨

範例:

▼設置錨點 (連結按了網頁不會重新整理)

<a href="#story">


▼js判斷錨點內容做動作

if(location.hash == "#story" || location.hash == "#character" || location.hash == "#background"){
$(".story_totalnav").addClass("active");
$(".navigation_2nd").fadeIn(500)
}else{
$(".story_totalnav").removeClass("active");
$(".navigation_2nd").fadeOut(500)
}

if(location.hash == "#ost"){
$(".ost_area").addClass("active")
}else{
$(".ost_area").removeClass("active")
}


留言

這個網誌中的熱門文章

PHP讀資料庫的資料,保留換行及空格

CSS animation 簡寫&好用的工具

使陣列裡的數值隨機重新排序