我的网页上有以下代码。 SetDivPosition和window.onload是在div标签和$(document).ready上回传滚动条位置。 功能是当用户第一次访问此页面时,滚动条需要一直到底部,这需要在用户优先时才进行一次 被重定向到页面。如果我第一次访问页面,滚动条一直到顶部。我希望它在底部 也支持回发上的滚动条位置。我此时只能做一件事,我可以保持滚动条位置或 将滚动条一直移动到底部。我能完成这两件事。
任何帮助将不胜感激。
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.9.1.js" type="text/javascript"></script>
<script src="Scripts/jquery.cookie.js" type="text/javascript"></script>
<script type = "text/javascript">
function SetDivPosition() {
var intY = document.getElementById("scrollArea").scrollTop;
document.cookie = "yPos=!~" + intY + "~!";
}
window.onload = function () {
var strCook = document.cookie;
if (strCook.indexOf("!~") != 0) {
var intS = strCook.indexOf("!~");
var intE = strCook.indexOf("~!");
var strPos = strCook.substring(intS + 2, intE);
document.getElementById("scrollArea").scrollTop = strPos;
}
}
$(document).ready(function () {
if ($.cookie("scriptExecuted") != "yes") {
//Scroll div you the bottom onpage load
$("#scrollArea").scrollTop($("#scrollArea")[0].scrollHeight);
$.cookie("scriptExecuted", "yes");
}
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="scrollArea" style="overflow-y: scroll; height: 260px; width: 300px" onscroll="javascript:SetDivPosition();">
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
This is some text.<br />
</div>
<asp:Button Text="Submit" runat="server" />
</form>
</body>
</html>