正在尝试滚动页面:未捕获类型错误:无法读取属性'top'的未定义

Trying to scroll a page: Uncaught TypeError: Cannot read property 'top' of undefined

本文关键字:读取 属性 未定义 错误 top 类型 滚动      更新时间:2023-09-26

我已经研究了其他问题,但没有成功。。。

我只是想在加载后保持页面缓慢滚动,遵循代码:

CSS(大多数CSS都作为嵌入文件放置,这只是应用于内容对象的样式):

<style type="text/css">
.content {
    width: 98%;
    left: 1%;
    margin-top: -10px;
}
.block_1 {
    position: relative;
    width: 18.5%;
    height: 150px;
    margin-left: 1%;
    margin-top: 1%;
    float: left;
    background: #FFF;
    border: 3px solid #999;
}
</style>

JS:

<script type="text/javascript">
$(function(){
    $.slidebars({
      siteClose: true
    });
});
// Loading
$(document).ready(function(){
    $(window).load(function(){
        $('.loading').fadeOut(700);
    });
});
$('html,body').animate({scrollTop: $('#end').offset().top});
</script>

HTML

<body>
<div class="loading">
  <div class="loading_msg">Carregando dados, aguarde...</div>
  <div class="loading_img"><img src="img/loader.gif" /></div>
</div>
<div class="sb-slidebar sb-left sb-width-custom" data-sb-width="300px"</div>
<div id="sb-site">
<div class="div_bg_header"><?php show_header_menu_dashboard($p_title); ?></div>
<div class="content" id="content">
  <div class="block_1"></div>
  <div class="block_1"></div>
  ...
  <a id="end"></a>
</div>
</div>
</body>

感谢

更正为

$(document).ready(function(){
    $(window).load(function(){
        $('.loading').fadeOut(700);
    });
  $('html,body').animate({scrollTop:$('#end').offset().top});
});

在你的CSS中,请为主体设置一些高度,

body {
     height: 1500px;          
     }

而且效果会很好。当前偏移量仅为16。所以对于可见滚动请添加以下样式。

#end {
       margin-top: 500px;
       display: block;
     }