我们有一个平滑的滚动脚本,在一些Mac机器上失败(最新的chrome)。
我们稍微调整了一下脚本,现在它似乎可以在所有Mac上运行了。
但是我们不知道为什么。
有人能帮帮忙吗?
之前(对于某些Mac/Chrome测试机,无法正确平滑滚动):
var topID = (ua("safari")) ? "body" : "html";
$(".SmoothScroll").unbind().click(function(){
var link = $(this).attr("href");
if(link.charAt(0)=="#" && link.charAt(1)!="") {
var offset = $(link).offset();
var tid = setTimeout(function() {
$(topID).stop().animate({scrollTop: offset.top}, 800, "easeInOutCubic", function() {
location.href = link;
});
}, 10);
return false;
}
});修复后(适用于所有计算机)
//var topID = (ua("safari")) ? "body" : "html";
var $root = $('html, body');
$(".SmoothScroll").unbind().click(function(){
var link = $(this).attr("href");
if(link.charAt(0)=="#" && link.charAt(1)!="") {
var offset = $(link).offset();
var tid = setTimeout(function() {
$root.stop().animate({scrollTop: offset.top}, 800, "easeInOutCubic", function() {
location.href = link;
});
}, 10);
return false;
}
});基本上,将$(topID)更改为$('html,body')似乎是可行的。但是为什么呢?发生了什么?之前的脚本在某些Mac+Chrome上失败的原因可能是什么?
发布于 2017-09-21 00:58:44
您可能在两台mac上安装了不同版本的safari。
https://stackoverflow.com/questions/46327682
复制相似问题