程序go 2016-03-19 18:09 采纳率: 100%
浏览 20

jQuery加载滚动后

I'm trying to scroll to the div that contains the results of a jquery load operation.
The ajax load works as expected but the page does not scroll after the load. Why doesn't this test code do this? Or, is there a better way?

Here is the test page that does not scroll after the load but does scroll if you then mouse click on the anchor hash tag (Go to...):

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div>line 1</div>
<div>line 2</div>
  <a id="idGoTo" href="#scrollTo">Go to...</a>

  <a name="scrollTo">SI</a>
  <div id="divRightSide">
      <!--   ajax content here -->
  </div>

<script type="text/javascript" src="/js/jquery/jquery-1.11.3.min.js"></script>
  <script>
  $(document).ready(function() {
      $("#divRightSide").load("/php/graduate/programs/clinical/programinformation_s.php", function() {
          $("#idGoTo").trigger("click");
          });
}
);
</script>
</body>
</html>

Thanks Much for any consideration

  • 写回答

2条回答 默认 最新

  • weixin_33697898 2016-03-19 18:16
    关注

    Try using .scrollTo as below:

    $(document).ready(function() {
          var _element=$("#divRightSide");
          _element.load("/php/graduate/programs/clinical/programinformation_s.php", function(){
               $('body').scrollTo("#"+_element.attr('id'));
          });
    });
    

    <kbd>Reference</kbd>

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度