目標:我正在更新一些現有內容(大量文本和多個頁面)以在動態jQuery滑塊(creator's demo page & code here)中隱藏/分段。但是,內容充滿了各個位置的內部鏈接,我不想單獨更新。 (a)創建jQuery自動檢測錨點位於哪個滑塊div,並自動打開它,或者(b)如果URL包含一個哈希標記,則觸發openAll函數以打開所有滑塊,然後滾動到錨點位置。jQuery打開所有滑塊元素,然後跳轉到錨點鏈接
問題:我是新手。我選擇了B選項,並認爲我的代碼有正確的想法,但它打破了頁面。想法?
var hash = location.hash.replace('#', '');
$('body').find('ul'+hash+':first');
function hashload {
if(window.location.hash) {
$('.collapsible').openAll();
$('html, body').animate({
scrollTop: $('#'+hash).offset().top}, 'fast');}}
相關資源可能有鑰匙給它的所有(又名什麼,我在此基礎...): Link to an anchor within JQuery tabbed content(和伴隨的解決方案在這裏:http://jsfiddle.net/TGMDd/65/)
don't execute script if url contains # ...和: Getting URL hash location, and using it in jQuery
JQuery scroll to anchor on click?
非常感謝您的時間!