我在google上搜索了我的问题的解决方案,我不明白为什么我写的代码对所有的工作,但对我来说不.
我写过:
<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,'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>
尝试这个: