2
I have this code but I don’t understand why the method .toggleClass()
is not functioning as expected to change the opacity of the element:
HTML
<div id="admin">
<p><br/>Admin</p>
<form method="POST" action="loginAdmin.php">Username:
<br/>
<input type="text" name="username" />
<br />Password:
<br/>
<input type="password" name="password" />
<br />
<div id="button">
<button id="btn" name="send" type="submit" value="enviar">Login</button>
</div>
</form>
</div>
CSS
#admin {
position: absolute;
margin-top: 140px;
right: 200px;
width: 224px;
z-index: 1;
height: 140px;
}
#admin p {
font-family: Lato-Light;
float: right;
cursor: pointer;
color: blue;
bottom: 0;
right: 15px;
position: absolute;
font-size: 11px;
opacity: 0.3;
}
.adminPvisible {
opacity:1;
}
#admin p:hover {
opacity: 1;
}
#admin form {
display: none;
font-family:Lato-Light;
font-size: 11px;
margin:35px 0 0 100px;
}
#btn {
display: none;
font-size: 12px;
margin: 5px 0 0 0;
font-family: Lato-Regular;
}
#admin input {
width: 120px;
font-size: 12px;
margin: 0;
height: 20px;
}
jQuery
$(document).ready(function () {
$('#admin > p').click(function () {
$(this).toggleClass('adminPvisible');
var right = $('#admin > p').css('right') == '135px' ? '0' : '135px';
$('#admin > p').animate({
right: right,
width: '50px'
});
$('#admin > form, #btn').stop(true).slideToggle();
})
})
In case it adds the ! Mportant is unnecessary and should usually be avoided. He just needs to specify better the rules to be applied, as said in Gustavo Rodrigues' reply
– Moykn