mercredi 18 février 2015

Javascript Event - Holding CTRL Key and mousover on button at the same time


Vote count:

0




I have two solutions so far but none of them work. Can anyone lead me in the right direction ?


I am trying to achieve the folowing:



  1. Hide text in a div

  2. User will press Ctrl key, then put his mouse over a button - a javascript function has to be called, and the text in the div should be displayed

  3. If the User releases the Ctrl key - the text should disappear (even if the mouse is on the button), similarly if the User moves the mouse out from the button - the text should disappear (even if the Ctrl key is pressed)


First try:



<html>
<head>
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script>
$(document).ready(function(){

$("#center").css("visibility","hidden"); //Hidden text in the beginning

$("#select").mouseover(function(e){
while(e.ctrlKey)
$("#center").css("visibility","visible");
$("#center").css("visibility","hidden");
}).mouseout(function(){
$("#center").css("visibility","hidden");
});
});
</script>
</head>

<body>
<button type="button" id="select">CTRL+mouseover</button>
<div id="center">
<h1>Text text text</h1>
</div>
</body>

</html>


The second try:


http://ift.tt/1FrTkkx


As a resume, the idea of the entire code is that holding CTRL + mouseover on a button reveals a hidden text. Can anyone lead me in the right direction ?



asked 2 mins ago

Alex

35






Javascript Event - Holding CTRL Key and mousover on button at the same time

Aucun commentaire:

Enregistrer un commentaire