我在 iframe 中有以下 jQuery 代码:
<script>
jQuery("#logBtn").click(function(){
jQuery("#content-promo").load("/path/to/file.php", function(response, status, xhr) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
$("#error").html(msg + xhr.status + " " + xhr.statusText);
}else{ //update
$("html, body").animate({ scrollTop: 0 }, "slow");
}
});
return false;
});
</script>
在AJAX请求之后iframe如何滚动回顶部?
答案 0 :(得分:1)
我找到了解决方案。我已将下面的代码添加到file.php
,现在可以使用了。
<script> window.parent.parent.scrollTo( 0, 800 ); </script>
答案 1 :(得分:0)
使用:
$('#my-frame').scrollTop();
答案 2 :(得分:0)
您可以使用此代码window.scrollTo(x-coord, y-coord);
,其中
Parameters
* x-coord is the pixel along the horizontal axis.
* y-coord is the pixel along the vertical axis.