我有一個html頁面的登錄和主頁。我有登錄用戶的條件。例如當他/她使用臨時密碼登錄時,重定向頁面的url將爲home.html?change=yes#focuschange
然後在我的主頁上當url change
== "yes"
時,它將隱藏其他div id(home-wrapper)。然後顯示focuschange
div ID。並應滾動到所述div ID。但是在加載主頁時,它只是隱藏其他div,並顯示focuschange
div,但不顯示滾動。它只顯示在底部。當我重新加載頁面時,它現在將按照我的意願滾動。這是爲什麼?我嘗試使用scrollIntoView()
和animate scrollTop
但同樣的問題。當Div id剛剛顯示在屏幕上時滾動頁面id:無顯示:block
我的HTML的結構是這樣的:
<div class="page-content">
<div class="content-block">
<div id="home-wrapper"></div> //this will hide upon page load (by default it will show)
<div id="profile-wrapper"> // this will show upon page load (by default it will hide)
<div id="info"></div>
<div id="focuschange">
<form></form>
</div>
</div>
</div>
</div>
而且這是在主頁上我的jQuery函數:
function GetURLParameter(sParam){
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
return sParameterName[1];
}
}
}
var urlvar = GetURLParameter('change');
if (urlvar == 'yes'){
$('#home-wrapper').hide();
$('#profile-wrapper').show();
setTimeout(function(){
$("#newpass").focus();
}, 200);
}
有滾動DIV ID的問題時,它只是顯示在加載頁面?
在這種情況下應該採取什麼方法?
我可能會誤解你的問題是什麼,但它看起來像你試圖使用「錨」與哈希以實現平滑滾動。是這樣嗎? – Piercey4
@ Piercey4是的,我只是想將頁面滾動到我的網址上的ID,這是'#focuschange' –