我有一个按钮可以固定页面内容的位置,然后在表单从右侧滑入时将其向左推。
这工作正常,除了一件事。当用户稍微向下滚动页面并单击按钮时,它成功地固定了位置。但是,当他们关闭此表单时,页面不会返回到原始位置......它会将用户带回页面顶部。我在下面发布了 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);
});
});
});
});