2014-10-04 62 views
0

我注意到這似乎在Chrome中不起作用。我找到了解決在線(即在演示的作品),但我不能讓它出於某種原因:jQuery ScrollTo Chrome Fix

這裏是我的代碼有:

$('#button-top').bind('click', function(e) { 
    try { 
     e.preventDefault(); 
     target = this.hash; 
     $('html, body').scrollTo(target, 150); 
    } catch (error) { 
     alert('error - ' + error); 
    } 
}); 

如果有幫助,這裏是一個鏈接我的網站建設(見頁面右下角的鏈接):

http://www.mattpealing.co.uk/_dev/

回答

2

您正在加載舊版本(1.4.2)的jquery.scrollTo。轉到latest version 1.4.13,它可以工作,看評論中的小提琴。

+0

這裏是一個工作小提琴:http://jsfiddle.net/072h7hsg/ – 2014-10-04 19:29:01

+0

這似乎是這個問題最合乎邏輯的答案,但我仍然認爲這個插件的使用是無關緊要的。 – 2014-10-04 19:32:44

+0

非常感謝! – pealo86 2014-10-16 13:28:03

0

JQuery的沒有任何scrollTo()功能。但是,它具有scrollTop(position)函數。

這樣的工作(我不知道你與你的150的意思):

$('#button-top').bind('click', function(e) { 
    try { 
     e.preventDefault(); 
     target = this.hash; 
     $('html, body').scrollTop(150); 
    } catch (error) { 
     alert('error - ' + error); 
    } 
}); 

如果這是你想要的,這將做的工作(有150毫秒的動畫速度)動畫:

$('#button-top').bind('click', function(e) { 
    try { 
     e.preventDefault(); 
     target = this.hash; 
     $('html, body').animate({ 
      scrollTop: 0 
     }, 150); 
    } catch (error) { 
     alert('error - ' + error); 
    } 
}); 
+0

但他包括從https://github.com/flesler/jquery.scrollTo的jquery.scrollTo庫。 – 2014-10-04 19:19:19

+0

我的不好,我沒注意到。問題是爲什麼在原生Jquery做他想做的事情時使用庫? – 2014-10-04 19:22:17

+0

是的,我也會使用'animate'方法。好吧。 – 2014-10-04 19:30:52