gpt4 book ai didi

javascript - jQuery UI .widgets 在隐藏时重置子项的滚动位置

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:37:07 25 4
gpt4 key购买 nike

我在我的最新项目中大量使用了 jQuery UI。不幸的是,由于 jQuery UI 小部件在包含带有用于溢出的滚动条的元素时表现出一些非常古怪的行为,我遇到了一个大问题。

Check out this demo

  1. .scroll-container 元素之一中向下滚动
  2. 点击 Accordion 标题
  3. 点击旧标题 - 请注意该元素已自动滚动到顶部。

有没有办法防止这种情况发生?它与我的一个使用 jQuery 滚动的主要插件搞混了。我完全不知道在这里做什么!

也许这是一个值得在 jQuery UI 开发论坛中提及的错误...

编辑

到目前为止,该错误已在...确认

  • Chrome - 8.0.552.231 OSX 10.6.5
  • Safari - 5.0.3 on OSX 10.6.5(有意义)
  • FF - 3.6.12 OSX 10.6.5

并且不存在在……

  • FF - 3.6.12 OSX 10.6.5

最佳答案

我遇到了同样的问题。我想出的一个解决方法是在创建后设置 ui 对象的 id。然后我在隐藏对象之前保存 scrollTop() 位置。当我再次显示该对象时,我只需将 scrollTop() 设置为保存的值。

// Set the id of the object if you have multiple objects with the same class
if ($("#divScroll").length == 0) { // If the object does not exist with an id
$(".ui-jqgrid-bdiv").each(function () { // Select each object via class
strID = $(this).attr("id");
// If the current object (selected via class) does not have an id, set id
if (strID == undefined || strID == false) {
$(this).attr("id", "divScroll");
}
});
}

// Save the scroll position before hide()
intScrollTop = $("#divScroll").scrollTop();
$("#divScroll").hide();

// Set the scroll position to the saved value after show()
$("#divScroll").show();
$("#divScroll").scrollTop(intScrollTop);

关于javascript - jQuery UI .widgets 在隐藏时重置子项的滚动位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4504625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com