怎样手动滑动div

我的body里有两个div,默认第一个div, height站满屏,有一个点击事件,点击事件中用什么方法能够滑动到屏幕的底部啊

阅读 3.4k
4 个回答

$("#div").animate({height:'0'});

<style>

body{margin: 0; padding: 0}

#content1{
    height: 100%;
    background-color: #00a0c6;
    width: 100%;
}

#content2{
    width: 100px;
    height: 100px;
    background-color: white;
    z-index: 100;
    float: left;
    position: fixed;
    top: 0;
}

</style>
<script>

$(function () {
 $('body').height(window.screen.height);
 $('body').width(window.screen.width);
})

</script>
<body>
<div id="content2"></div>
<div id="content1"></div>
<script>

$('#content1').click(function () {
    $('#content2').animate({top:'85%'});
})

</script>

我用的这种方法

function scrollToBottom() {
    window.scrollTo(0,document.body.scrollHeight);
}

主要代码:

    let toPos=document.body.scrollTop+window.innerHeight;
    window.scroll(0,toPos);

内容不超过屏幕一屏 第二个DIV 往上滑,就用CSS3

滑动滚动条 就用scrollTo

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题