Javascript Safari(Mac OS)上的jQuery平滑滚动问题
我在Safari上遇到了一个奇怪的问题(仅限Mac OS,Windows运行良好),我的平滑滚动没有滚动。它只是跳转到链接,但在所有其他浏览器中都有效,甚至在WindowsSafari上也是如此 我的jQuery是Javascript Safari(Mac OS)上的jQuery平滑滚动问题,javascript,jquery,html,safari,Javascript,Jquery,Html,Safari,我在Safari上遇到了一个奇怪的问题(仅限Mac OS,Windows运行良好),我的平滑滚动没有滚动。它只是跳转到链接,但在所有其他浏览器中都有效,甚至在WindowsSafari上也是如此 我的jQuery是 <script type="text/javascript"> (function($){ $.extend({ smoothAnchors : function(speed, easing, redi
<script type="text/javascript">
(function($){
$.extend({
smoothAnchors : function(speed, easing, redirect){
speed = speed || "slow";
easing = easing || null;
redirect = (redirect === true || redirect == null) ? true : false;
$("a").each(function(i){
var url = $(this).attr("href");
if(url){
if(url.indexOf("#") != -1 && url.indexOf("#") == 0){
var aParts = url.split("#",2);
var anchor = $("a[name='"+aParts[1]+"']");
if(anchor){
$(this).click(function(){
if($(document).height()-anchor.offset().top >= $(window).height()
|| anchor.offset().top > $(window).height()
|| $(document).width()-anchor.offset().left >= $(window).width()
|| anchor.offset().left > $(window).width()){
$('html, body').animate({
scrollTop: anchor.offset().top,
scrollLeft: anchor.offset().left
}, speed, easing, function(){
if(redirect){
window.location = url
}
});
}
return false;
});
}
}
}
});
}
});
})(jQuery);
</script>
(函数($){
$.extend({
smoothAnchors:函数(速度、缓和、重定向){
速度=速度| |“慢”;
放松=放松| |空;
重定向=(重定向===true | |重定向==null)?true:false;
$(“a”)。每个(功能(i){
var url=$(this.attr(“href”);
如果(url){
if(url.indexOf(“#”)等于-1&&url.indexOf(“#”)等于0){
var aParts=url.split(“#”,2);
var-anchor=$(“a[name='”+aParts[1]+'”);
如果(锚){
$(此)。单击(函数(){
if($(文档).height()-anchor.offset().top>=$(窗口).height()
||anchor.offset().top>$(窗口).height()
||$(文档).width()-anchor.offset().left>=$(窗口).width()
||anchor.offset().left>$(window.width()){
$('html,body')。设置动画({
scrollTop:anchor.offset().top,
scrollLeft:anchor.offset().left
},速度,放松,功能(){
如果(重定向){
window.location=url
}
});
}
返回false;
});
}
}
}
});
}
});
})(jQuery);
我的HTML是这样的
<nav id="nav">
<ul id="navigation">
<li><a href="#About" class="fade"> ABOUT</a></li>
<a name="About"></a>
如果有人知道是什么问题,请告诉我
非常感谢。非常适合我
(function($) {
$.fn.SmoothAnchors = function() {
function scrollBodyTo(destination, hash) {
// Change the hash first, then do the scrolling. This retains the standard functionality of the back/forward buttons.
var scrollmem = $(document).scrollTop();
window.location.hash = hash;
$(document).scrollTop(scrollmem);
$("html,body").animate({
scrollTop: destination
}, 200);
}
if (typeof $().on == "function") {
$(document).on('click', 'a[href^="#"]', function() {
var href = $(this).attr("href");
if ($(href).length == 0) {
var nameSelector = "[name=" + href.replace("#", "") + "]";
if (href == "#") {
scrollBodyTo(0, href);
}
else if ($(nameSelector).length != 0) {
scrollBodyTo($(nameSelector).offset().top, href);
}
else {
// fine, we'll just follow the original link. gosh.
window.location = href;
}
}
else {
scrollBodyTo($(href).offset().top, href);
}
return false;
});
}
else {
$('a[href^="#"]').click(function() {
var href = $(this).attr("href");
if ($(href).length == 0) {
var nameSelector = "[name=" + href.replace("#", "") + "]";
if (href == "#") {
scrollBodyTo(0, href);
}
else if ($(nameSelector).length != 0) {
scrollBodyTo($(nameSelector).offset().top, href);
}
else {
// fine, we'll just follow the original link. gosh.
window.location = href;
}
}
else {
scrollBodyTo($(href).offset().top, href);
}
return false;
});
}
};
})(jQuery);
$(document).ready(function() {
$().SmoothAnchors();
});
谢谢!这似乎对我也适用。我不确定是什么打嗝,但它100%起作用了!谢谢。它落在Safary上了,对不起-1。@我想这是Alex的问题,不是我的;-)