2013-07-03 155 views
0

我試圖讓一個彈出div來點擊鏈接時顯示一些內容。jQuery fadeIn/fadeOut不工作

的jQuery:

$(document).ready(function() { 

    //Popup Content Script 
    $("#services").click(function(){ 

     servicesPopup(); 

    }); 

    $(".popupClose").click(function() { 

     closePopupFunction(); 

    }); 

    function servicesPopup() { 

     $(".popup").fadeIn("slow", function() { 

      $(".container").css("opacity", ".3"); 
      $(".popup").html("This is a test.\n\ 
      This is a test.\n\ 
      This is a test.\n\ 
      This is a test.\n\ 
      This is a test."); 

     }); 
    }; 

    function closePopupFunction() { 

     $(".popup").fadeOut("slow"); 
     $(".popup").html(""); 
     $(".container").css("opacity","1"); 


    }; 

    }); 

HTML:單擊該按鈕時

<li><a href="#" class="button" id="services" title="Learn about all of our services."><span>Services</span></a></li> 

什麼也沒有發生。我盡我所能地想方設法改變代碼和HTML,但都沒有成功。我在這裏進行了一次搜索,沒有發現任何內容以及對所有jQuery代碼的完整查詢,並且找不到答案。感謝您的任何幫助。

+0

寫這些功能'servicesPopup()'和'closePopupFunction()''中的document.ready function'外面再試試。 –

+0

@RohanKumar - 沒有必要,他們在範圍內。 – nnnnnn

+1

Joe - 「.popup」和「.container」的html在哪裏?你的代碼如下所示應該做_something,_即使淡出等等不是你所期望的:http://jsfiddle.net/b23Yz/(我發明了一些html來匹配你的JS,但把關閉事件放在一個文件點擊,而不是在任何'.popupClose'上。) – nnnnnn

回答

0

試試這個,

function servicesPopup() { 
    $(".popup").fadeIn("slow", function() { 
     $(".container").css("opacity", ".3"); 
     //Also write the string in a single line or escape it 
     $(".popup").html("This is a test.<br/>This is a test.<br/>This is a test."); 
    }); 
} 

function closePopupFunction() { 
    $(".popup").fadeOut("slow"); 
    $(".popup").html(""); 
    $(".container").css("opacity","1"); 
} 


$(document).ready(function() { 
    //Popup Content Script 
    $("#services").click(function(e){ 
     e.preventDefault(); 
     servicesPopup(); 
    }); 

    $(document).on('click',".popupClose",function() { 
     closePopupFunction(); 
    });  
}); 
+0

我不知道這是否重要,但我正在使用WAMP。 –