Jquery 在Windows Phone上,在IE中将动画平滑滚动到页面的各个部分
我有一个包含各个部分的页面和指向这些部分的链接。我已使用以下内容实现了滚动动画:Jquery 在Windows Phone上,在IE中将动画平滑滚动到页面的各个部分,jquery,windows-phone,Jquery,Windows Phone,我有一个包含各个部分的页面和指向这些部分的链接。我已使用以下内容实现了滚动动画: $(function() { $('a[href*=#]:not([href=#])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var target = $
$(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;
}
}
});
});
这在Chrome、Safari、Firefox以及iOS 7和Android上都能很好地工作,但在Windows Phone(8带IE)上,滚动的速度很快,页面的顶部也不见了
有什么办法让它工作吗?IE有一个“平滑滚动”功能的bug,动画在滚动之后才会启动 默认情况下,IE11的所有win8用户都可以使用该选项 下面是我用来修复固定头上的抖动
if(navigator.userAgent.match(/Trident\/7\./)) {
$('body').on("mousewheel", function () {
event.preventDefault();
var wd = event.wheelDelta;
var csp = window.pageYOffset;
window.scrollTo(0, csp - wd);
});
}