【问题标题】:jump to id with animation用动画跳转到 id
【发布时间】:2013-11-27 05:32:55
【问题描述】:

我正在根据以前的人重建一个网站。这里是源码,点击时使用id跳转。

<a href="#faq01">Cancel or Modify an Order</a>

点击跳转到

<a name="faq01" id="faq01"></a><strong>Cancel or Modify an Order</strong></p>
<p> Please kindly contact our customer service to cancel or modify your order. However, once your order has been processed and ...</p>

有没有一种简单的方法可以使这种跳跃顺利进行?类别非常大,但格式相同。

【问题讨论】:

标签: javascript jquery html


【解决方案1】:

用这个,希望对你有帮助

$(function() {
  $('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
      if (target.length) {
        $('html,body').animate({
          scrollTop: target.offset().top
        }, 1000);
        return false;
      }
    }
  });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-27
    • 2011-10-08
    • 1970-01-01
    • 2021-04-18
    相关资源
    最近更新 更多