我有一个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' –