我在谷歌上搜索了我的问题的解决方案,但我无法理解为什么我编写的代码对每个人都有效,但对我不起作用。
我写过这个:
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
function scrollTo() {
$('html, body').animate({ scrollTop: $('#div_id').offset().top }, 'slow');
return false;
}
</script>
<style type="text/css">
.uno {
height: 1000px;
background: #808080;
}
.due {
margin-top: 300px;
height: 500px;
background: #ff00ff;
}
</style>
</head>
<body>
<div class="uno" onclick="scrollTo()">
Clicca
</div>
<div class="due" id="div_id"></div>
</body>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
function scrollTo() {
$('html, body').animate({ scrollTop: $('#div_id').offset().top }, 'slow');
return false;
}
</script>
<style type="text/css">
.uno {
height: 1000px;
background: #808080;
}
.due {
margin-top: 300px;
height: 500px;
background: #ff00ff;
}
</style>
</head>
<body>
<div class="uno" onclick="scrollTo()">
Clicca
</div>
<div class="due" id="div_id"></div>
</body>
</html>
尝试这个:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)