滚动到 iframe 中数据表的顶部
Scroll to top of datatable in an iframe?
我正在尝试向我的DataTables
添加一个函数,当单击分页链接时,该函数会滚动到表格顶部,我按照这里的指南进行操作:
http://jsfiddle.net/EjbEJ/
function paginateScroll() {
$('html, body').animate({
scrollTop: $(".dataTables_wrapper").offset().top
}, 100);
console.log('pagination button clicked');
$(".paginate_button").unbind('click', paginateScroll);
$(".paginate_button").bind('click', paginateScroll);
}
paginateScroll();
这很完美,但不幸的是,我有DataTable
的页面正在加载到 iframe 中,而在 iframe 中它不再工作。知道如何让这个脚本在 iframe 中工作吗?
是的,您必须使用 postMessage 与 iframe 通信,并且可能在两个位置都有您的代码,以便父框架可以向框架发送消息,然后框架可以执行滚动动画。
https://davidwalsh.name/window-postmessage
只是为了让你知道我解决了这个问题。我只需要添加$(parent.document).find来获取父框架的html和body标签。
function paginateScroll() {
$(parent.document).find('html, body').animate({
scrollTop: $(".dataTables_wrapper").offset().top
}, 100);
//console.log('pagination button clicked');
$(".paginate_button").unbind('click', paginateScroll);
$(".paginate_button").bind('click', paginateScroll);
}
paginateScroll();
干杯
相关文章:
- 用程序搜索JQuery数据表中的文本
- 具有rowGrouping的数据表无法隐藏列
- 使用谷歌应用程序脚本将服务器端数据表返回到客户端
- 将单击事件添加到数据表
- 使用带有参数的数据表sAjaxSource
- 对角度数据表中括号内的数字进行排序
- 动态构建一个数据表与scriplets
- jquery数据表的自定义ko绑定
- 预览数据表单
- 如何在数据表中设置从Ajax响应选中的复选框
- DT数据表背景颜色为黑色,但仍有悬停和选择颜色
- 数据表-隐藏/显示列
- 如何以编程方式将所需行移动到数据表的顶部
- 数据表在页面更改时滚动顶部
- 为什么数据表在我的表顶部添加行
- 数据表个人搜索在放置在网格顶部时不起作用
- 滚动到 iframe 中数据表的顶部
- 顶部水平滚动条数据表javascript
- 顶部的Jquery数据表静态行
- 数据表水平滚动条将显示在顶部而不是底部