我有一个固定页面内容位置的按钮,然后在表单从右侧滑入时将其向左推。
这很正常,除了一件事。当用户略微向下滚动页面并单击按钮时,它成功地确定了位置。但是,当他们然后关闭此表单时,页面不会返回到原始位置...它将用户带回到页面顶部。我在下面发布了jquery,这可能有助于更好地解释问题。
这里还有一个jsfiddle示例...
var pageContents;
var currentscrollpos;
$(document).ready(function() {
$("a#testbutton").live('click', function() {
var currentscrollpos = $(window).scrollTop();
var pageContents = $("body").html();
$("body").html("");
$("<div class='pageContainer'>" + pageContents + "</div>").prependTo("body");
$(".pageContainer").css({'position':'fixed','top':currentscrollpos*-1});
$("html, body").animate({ scrollTop: 0 }, 0);
$("<div class='blackout'></div>").appendTo("body");
$(".blackout").css("opacity",0.8).fadeIn('slow', function() {
$("<div class='popupPanel'><a class='closeme'>close</a></div>").appendTo("body");
$(".popupPanel").animate({
right: "0px"
}, 500, function() {
$(".popupPanel").css("position","absolute")
});
$(".pageContainer").animate({
left: "-200px"
}, 500, function() {
});
$("a#testbutton").append(currentscrollpos)
});
return false;
});
$('.closeme').live('click', function() {
var pageContents = $(".pageContainer").html();
$(".popupPanel").css("position","fixed").animate({
right: "-200px"
}, 500, function() {
});
$(".pageContainer").animate({
left: "0px"
}, 500, function() {
$(".blackout").fadeOut('slow', function() {
$(".blackout").remove();
$("body").html(pageContents);
$("html, body").animate({ scrollTop: currentscrollpos }, 0);
});
});
});
});
您正在使用local
您可以使用此代码返回从浏览器关闭的页面的位置