我目前使用fullPage.js作爲website I'm creating。請注意,如果滾動,它會在URL上附加一個散列(例如,#feature1
)。我想基於散列更改圖像和背景圖像中如何在使用fullpage.js時根據URL哈希更改圖像?
這是我上面的標籤<body>
初始化我使用這個JavaScript來嘗試改變形象fullPage.js
$(document).ready(function() {
$('#fullpage').fullpage({
anchors: ['welcome', 'feature1', 'feature2', 'feature3', 'feature4', 'feature5', 'feature6'],
sectionsColor: ['transparent', '#1BBC9B', '#7E8F7C', '#C63D0F', '#1BBC9B', '#7E8F7C'],
navigation: true,
navigationPosition: 'left',
});
});
,雖然我很確定document.write
是錯誤的。
$(document).ready(function() {
// Which anchor is being used?
switch(window.location.hash) {
case "#feature1":
document.write('<img class="screen" src="img/bg-feature-2.jpg">');
break;
case "#feature2":
document.write('<img class="screen" src="img/bg-feature-1.jpg">');
break;
}
});
如果我滾動到#feature1或#feature2它什麼都不做。但是,如果我將帶有散列的URL直接輸入到瀏覽器中,則只顯示圖像,而不顯示其他內容。我該如何解決這個問題?
的全頁插件提供了多種回調方法如'afterSlideLoad'和'onSlideLeave'。使用這些將是實現你想要的現有代碼的最佳方式。例如,查看[documentation](https://github.com/alvarotrigo/fullPage.js/)。 –
保羅,你看到我的答案了嗎? –