Необходимо создать картинку 300px на 300px, добавить возможность приближать и отдалять с помощью клавиш "+" и "-".
Не могу задать новое CSS значение элементу после условия if
. К примеру, простой alert
также не выводится.
$(document.body).append('<div class="div1" style="position:relative;border:5px solid black; width:300px; height:300px;"</div>');
$('.div1').append('<img id="img1" src="images/10.jpg" style="position: absolute; margin: auto;top: 0; left: 0; bottom: 0; right: 0; width: 300px; height: 300px;"/>');
$(document).ready(function() {
$(document).keypress(function(event) {
a = $('img').height(); //height
b = $('img').width(); //width
c = parseInt(a) + 10; //width plus one step Intvalue
d = parseInt(b) + 10; //height plus one step Intvalue
e = parseInt(a) - 10; //width minus one step Intvalue
f = parseInt(b) - 10; //height minus one step Intvalue
if (event.keyCode == 107) {
$('img').css('width', d + 'px') //change css Intvalue + "px"
$('img').css('height', c + 'px') //change css Intvalue + "px"
}
if (event.keyCode == 109) {
$('img').css('height', e + 'px')//change css Intvalue + "px"
$('img').css('width', c + 'px')//change css Intvalue + "px"
}
})
})