2016-10-19 3 views
0

jsを使用してポップアップモーダルで簡単にしようとしましたが、私は下のコードを持っていますが、どこでトランジションスタイルを追加するのかはわかりません。それのjsで行う。jsポップアップモーダルで楽にする方法

私のコードは以下の通りです。

// Get the modal 
var modal = document.getElementById('loginModal'); 

// Get the button that opens the modal 
var btn = document.getElementById("login"); 

// Get the <span> element that closes the modal 
var span = document.getElementsByClassName("close")[0]; 

// When the user clicks on the button, open the modal 
btn.onclick = function() { 
    modal.style.display = "block"; 
    modal.style.fadeIn(3000); 
} 

// When the user clicks on <span> (x), close the modal 
span.onclick = function() { 
    modal.style.display = "none".fadeIn(3000); 
} 

// When the user clicks anywhere outside of the modal, close it 
window.onclick = function(event) { 
    if (event.target == modal) { 
     modal.style.display = "none"; 
    } 
} 

答えて

1

はjQueryのを使用します。

window.onclick = function(event) { 
if (event.target == modal) { 
    $("#loginModal").fadeOut(3000) 
} 
} 

3000を使用すると、移行がなりたいミリ秒の量を表します。 フェードインとフェードアウトの詳細については、このリンクをクリックしてください: http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_eff_fadeout_fadein

+0

ここで私はそれを入れますか?私は申し訳ありませんおい、jqueryに新しいです。 –

+0

@OwenDawsonのクリックイベント機能です。閉じる:fadeOutとfadeInを開くために、私はあなたの例を示すために私の答えを編集しました – G43beli

関連する問題