![](/img/trans.png)
[英]I got an scroll position problems when I link anchor from page1 to page2 with a fixed header
[英]Page scroll to right page from menu anchor but not from direct link
我正在使用這個免費腳本
http://codyhouse.co/gem/css-faq-template/
http://codyhouse.co/demo/faq-template/index.html#payments
該演示與我的網站存在相同的問題,盡管在我的網站上甚至更糟。
如果使用菜單,則一切正常。 標頭上方有一些空間。
但是,如果您不通過菜單訪問直接鏈接http://codyhouse.co/demo/faq-template/index.html#payments
看起來像這樣
如您所見,標題“付款”上方沒有空格。
在我的頁面上甚至更糟。 它從“我可以擁有..”開始,並且標題被隱藏。 當我直接從鏈接訪問頁面時,找不到在哪里可以調整此設置,而沒有影響我從菜單訪問該部分時的外觀。
當用戶單擊某個部分時
//select a faq section
faqsCategories.on('click', function(event){
event.preventDefault();
var selectedHref = $(this).attr('href'),
target= $(selectedHref);
if( $(window).width() < MqM) {
faqsContainer.scrollTop(0).addClass('slide-in').children('ul').removeClass('selected').end().children(selectedHref).addClass('selected');
closeFaqsContainer.addClass('move-left');
$('body').addClass('overlay');
} else {
$('body,html').animate({ 'scrollTop': target.offset().top - 69}, 200);
}
});
Javascript代碼: http : //codyhouse.co/demo/faq-template/js/main.js
似乎這里有兩個問題。 對我來說,滾動事件觸發時,一切似乎都會發生。
嘗試這個:
$(document).ready(function(){
$(window).scroll();
})
只需快速破解,即可使用
if(window.location.hash) {
// if url contain '#'
// scroll down a few pixle
}
編輯:
很難在jsfiddle中對此進行解釋,因為它不會讓我玩#哈希。
var url = 'http://example.com/test.html#hash';
//you can get by using window.location.href
var hash = url.split('#')[1];
// this get the 1st hash variable
if(hash) {
// if hash exist
$('html, body').animate({
scrollTop: "5000px"
}, 0);
// scroll down a little bit
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.