i came across this question while searching for the exact same thing.
basically i have a text area and a button. button.click is triggered when the user press enter. however the :active selector in css is not triggered so it doesnt give the same affect.
so this is what i did. its a little redundant but works.
in the css
/*this is for actual clicks on the button */
.Button:active {
position:relative;
top:5px;
}
/* this is for pressing enter instead of clicking the button */
.Button.activate{
position:relative;
top:5px;
}
then in jquery
//if enter is pressed, trigger button click
$("#textArea").keydown(function(event){
if(event.keyCode == 13){
$("#button").click();
$("#button").addClass('activate');
}
});
//if enter is released, remove class
$("#textArea").keyup(function(event){
if(event.keyCode == 13){
$("#button").removeClass('activate');
}
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…