keydown/keyup toggle functionality
I'm trying to understand how I might toggle on/off functionality while a key is pressed. I've been working on an example but I'm struggling with how to select the element I'm currently interacting with so I can revert functionality once the key is released.
Below is the code I'm currently working on. On lines 6, 16 and 17 I would really like to select the specific element that was being resized, not all items in that class. How can I reference that specific item to toggle it's settings?
- $(document).keydown(function(e) {
- var keyCode = e.keyCode || e.which;
- if (keyCode == 18){
-
- $(".onpage").resizable({
- alsoResize: false,
- aspectRatio: false
- });
- }
- });
- $(document).keyup(function(e) {
- var keyCode = e.keyCode || e.which;
- if (keyCode == 18){
- $(".onpage").resizable({
- alsoResize: $(".onpage").find('img'),
- aspectRatio: true
- });
- }
- });
Thanks,
Dave