我有这个指令来提供动画ScrollTo:
.directive('scrollOnClick', [function() {
return {
restrict: 'A',
link: function(scope, $elm, attrs) {
var idToScroll = attrs.href;
$elm.on('click', function(e) {
var $target;
if (idToScroll) {
$target = $(idToScroll);
} else {
$target = $elm;
}
$("body").animate({
scrollTop: $target.offset().top
}, "slow");
e.preventDefault();
});
}
,HTML是:
<li><a href="#section1" scroll-on-click>Learn More</a></li>
这在Chrome中运行良好,但在IE 9或IE 11中,单击链接时没有响应。有什么想法吗?