如何在选择选项中滚动流体锚

时间:2013-12-23 16:00:50

标签: javascript jquery html

我无法使用select选项元素进行流体滚动,只能使用链接。任何人都可以帮助我吗?

jsfiddle demo

$(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;
      }
    }
  });
});

谢谢!

1 个答案:

答案 0 :(得分:2)

只是做:

DEMO

$('select').on('change', function () {
         $('html,body').animate({
                    scrollTop: $(this.value).offset().top
                }, 1000);
    });

并删除onchange内联属性