当从另一个选项卡更改时,jQuery应该返回到选项卡中完全相同的垂直位置
如果你看到这个提琴演示,它正在工作,但我真正想要的是它滚动到完全相同的位置(在标签“一”),因为我上次离开它(所以黄色/点击线不一定是第一行)。相反,它会滚动到单击的行,但在显示活动/单击的行之前,我需要更多的上下文 HTML:当从另一个选项卡更改时,jQuery应该返回到选项卡中完全相同的垂直位置,jquery,jquery-ui,Jquery,Jquery Ui,如果你看到这个提琴演示,它正在工作,但我真正想要的是它滚动到完全相同的位置(在标签“一”),因为我上次离开它(所以黄色/点击线不一定是第一行)。相反,它会滚动到单击的行,但在显示活动/单击的行之前,我需要更多的上下文 HTML: 这有可能吗?我自己用插件修复了这个问题-现在它返回到与我上次离开时完全相同的垂直位置 单击列表中的一行(在选项卡1中)时,我将位置保存到cookie中,单击选项卡1后,它将从cookie中获取旧位置并向下滚动到该位置 我替换了这个代码: $(".edit").click
这有可能吗?我自己用插件修复了这个问题-现在它返回到与我上次离开时完全相同的垂直位置 单击列表中的一行(在选项卡1中)时,我将位置保存到cookie中,单击选项卡1后,它将从cookie中获取旧位置并向下滚动到该位置 我替换了这个代码:
$(".edit").click(function (e) {
e.preventDefault(); // prevent the window/page to jump to the top
// Change focus to tab "two" (0-based index so this is the 2nd tab)
$("#tabsMain").tabs("option", "active", 1);
。。使用此代码(我刚刚添加了cookie部分-没有更改/删除任何内容):
注意,“e.preventDefault()”也可以删除——我发现它在这里没有任何用处
我还替换了这个:
$("#tab_one").click(function (event) {
if (oldTabIndex == 1) {
if ($("#selectedRow").length > 0) {
$('html, body').animate({
scrollTop: $("#selectedRow").offset().top
}, 500);
}
}
});
。。为此:
$("#tab_one").click(function (event) {
if (oldTabIndex == 1) {
var scrollPos = $.cookie("scrollPos"); // get the "scrollPos" cookie
$('html, body').animate({
scrollTop: scrollPos
}, 500);
}
});
我无法让Fiddle演示包含jquery cookie插件(?):-/您不想要黄色的活动颜色或滚动到单击的项目?我仍然想要黄色。现在,它是“手动”滚动到我单击的黄色/活动行(当我从选项卡2返回到选项卡1时),但理想情况下,它应该显示与我单击前留下的选项卡完全相同的选项卡(在选项卡1中)。或者我可以保存另一个位置,它可以滚动到黄线以外的位置,这样它就返回到相同的位置了?
$(".edit").click(function (e) {
e.preventDefault(); // prevent the window/page to jump to the top
// Set a cookie named "scrollPos" which lives for 7 days
var scrollPos = $(window).scrollTop();
$.cookie("scrollPos", scrollPos, {
path: '/',
expires: 7
});
// Change focus to tab "two" (0-based index so this is the 2nd tab)
$("#tabsMain").tabs("option", "active", 1);
$("#tab_one").click(function (event) {
if (oldTabIndex == 1) {
if ($("#selectedRow").length > 0) {
$('html, body').animate({
scrollTop: $("#selectedRow").offset().top
}, 500);
}
}
});
$("#tab_one").click(function (event) {
if (oldTabIndex == 1) {
var scrollPos = $.cookie("scrollPos"); // get the "scrollPos" cookie
$('html, body').animate({
scrollTop: scrollPos
}, 500);
}
});