2016-03-01 96 views
1

在我的Rails應用程序,我使用jQuery淡入在我的導航欄,並在主頁上一些文字淡出,如下點擊一個鏈接不會觸發jQuery的淡入

$(document).ready(function(){ 
    $('.jq-fadein').hide().delay(600).fadeIn(2000); 
}); 

它正常工作,每次我重新加載/刷新頁面,但是當我點擊導航欄中的主頁按鈕時,效果不起作用!

我懷疑,也許它不是發送一個GET請求,但因爲我發現了它的作用:

Started GET "/" for ::1 at 2016-03-01 01:44:18 +0100 
Processing by SiteController#index as HTML 
    Blog Load (1.5ms) SELECT "blogs".* FROM "blogs" ORDER BY "blogs"."id" ASC LIMIT 3 
    Rendered site/index.html.erb within layouts/application (4.3ms) 
    Rendered shared/_navbar.html.erb (1.3ms) 
    Rendered shared/_footer.html.erb (0.2ms) 
Completed 200 OK in 125ms (Views: 98.3ms | ActiveRecord: 1.5ms) 

我怎樣才能得到它的淡入,當我在導航欄上的主頁按鈕,點擊並不會刷新這一頁?

在此先感謝!

+1

看樣子你缺少home鍵點擊邏輯。你可以補充一點嗎? – DinoMyte

回答

0

您只調用$(document).ready()中的fadeIn函數,這會在頁面初始加載時觸發。這就是爲什麼你每次刷新時都會看到淡入淡出的原因。

添加淡入當你點擊home鍵應該是簡單的東西是這樣的:

$('#homeButton').click(function() { 
    $('.jq-fadein').hide().delay(600).fadeIn(2000); 
}); 
+0

我對jquery仍然很陌生,但現在它是有道理的。非常感謝 :) – fardin