我正在尝试向我的DataTables
添加一个函数,当点击分页链接时,该函数会滚动到表格的顶部,并且我已按照指南进行操作:
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中运行吗?
答案 0 :(得分:0)
是的,您必须使用postMessage与iframe进行通信,并且可能在两个地方都有您的代码,因此父框架可以向框架发送消息,然后框架可以执行滚动动画。
答案 1 :(得分:0)
只是为了让你知道我解决了这个问题。我只需要添加$(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();
干杯