使用jquery锚定html速度

使用jquery锚定html速度,jquery,html,anchor,pagespeed,Jquery,Html,Anchor,Pagespeed,我使用这段代码来设置我的锚速度,但它在IE(7、8、9和10)和firefox上不起作用。有人能告诉我我做错了什么,以及如何优化锚定速度吗 $('a.anchorlinks').on('click', function(e){ e.preventDefault(); var divId = $(this).attr('href'); var position = $(divId).position();

我使用这段代码来设置我的锚速度,但它在IE(7、8、9和10)和firefox上不起作用。有人能告诉我我做错了什么,以及如何优化锚定速度吗

$('a.anchorlinks').on('click', function(e){
            e.preventDefault();
            var divId = $(this).attr('href');
            var position = $(divId).position();
            $('body').animate({scrollTop: position.top}, 1000);
        });

使用offset()代替position

a.anchorlinks

position:relatve

是的,您也可以尝试使用offSet()

开发人员的工具中会产生哪些错误?(F12)这正是我的问题,因为我看不到任何错误,IE中的“错误显示”也被激活,我使用jquery 1.10,我尝试使用旧版本,但始终是相同的问题我认为你的
位置
什么都不是,因为你试图获得
href
标记的顶部位置。我尝试过这个,但不起作用,offset()和position(),是否存在设置ancher速度的其他方法?