Javascript 让一些内部链接动画正常工作

Javascript 让一些内部链接动画正常工作,javascript,jquery,Javascript,Jquery,我有一个脚本,可以打开一个新页面并向下滚动到一个id var jump = function (e) { if (e) { e.preventDefault(); var target = $(this).attr("href"); } else { var target = location.hash; } $('html,body').animate( { scrollTop: $(target).offset().top }, 2000, function (

我有一个脚本,可以打开一个新页面并向下滚动到一个id

var jump = function (e) {
 if (e) {
  e.preventDefault();
  var target = $(this).attr("href");
 } else {
  var target = location.hash;
 }

 $('html,body').animate(
 {
  scrollTop: $(target).offset().top
 }, 2000, function () {
  location.hash = target;
 });

 }

 $('html, body').hide();

 $(document).ready(function () {
  $('a[href^=#]').bind("click", jump);

  if (location.hash) {
   setTimeout(function () {
   $('html, body').scrollTop(0).show();
   jump();
  }, 0);
 } else {
  $('html, body').show();
 }
});

我想做的是,让它动画与内部链接在当前页面上的滚动。我如何整合它?

最简单的方法就是使用链接

它不需要jQuery或javascript,只需要使用id作为
href
值添加到HTML中的一些元素

<a id='exampleTop' href='#exampleMiddle'>I'm an example! Click to go down</a>

您最终解决了问题吗?