我試圖按下「登錄」按鈕時淡入一個登錄框。直到按下「登錄」按鈕,我希望該框被隱藏起來,以便它不能被看到或與之交互(我不確定是否沒有可見性會阻止它的按鈕被點擊 - 可能是指針事件可能儘管如此)。ToggleFade顯示一個元素:無?
除了第一次按下隱藏類被刪除(顯示框)的按鈕時,切換工作得非常好,但是切換淡出了該框。
HTML:
<a id="loginBtn" class="loginBtn" href="/">Login</a>
<div id="loginContainer" class="loginContainer hide">
<a class="registerBtn" href="/">Register</a>
</div>
CSS:
.loginBtn {
color: #1493d1;
background: #fff;
border-radius: 98px;
cursor: pointer;
margin: 15px 0 0 0;
padding: 8px 15px;
position: absolute;
right: 0px;
/*float: right;*/
text-decoration: none;
}
.loginContainer {
width: 175px;
height: 250px;
background: #fff;
border-radius: 10px;
position: absolute;
top: 80px;
right: 0px;
/*float: right;*/
}
.hide {
display: none !important;
}
JS:
$(document).ready(function() {
var loginBtn = document.getElementById("loginBtn");
//DISPLAY MOBILE NAVIGATION ON HAMBURGER CLICK
function displayLogin() {
$('#loginContainer').removeClass("hide");
$('#loginContainer').fadeToggle("fast");
}
//EVENT LISTENERS
loginBtn.addEventListener("click", displayLogin);
}); //Doc Ready
Unfortunatley無法正常工作,除了添加防止默認值之外,您是否更改過其他任何內容? – Xander
請再次檢查我的答案,我已經添加了e.preventDefault並更改了添加類的位置。 'e.preventDefault(); $('#loginContainer')。fadeToggle(「fast」); $('#loginContainer')。removeClass(「hide」);' –
先到iTunes然後刪除類。請檢查我的摘錄。 –