Hello.
Help with a little js code.
There are only two inputs for selecting the width and height without the form and buttons, and it is necessary that the picture smoothly changes its dimensions, which will be entered into these inputs.
Hello.
Help with a little js code.
There are only two inputs for selecting the width and height without the form and buttons, and it is necessary that the picture smoothly changes its dimensions, which will be entered into these inputs.
Our img:
<img src="images/logo/icon-256.png" class="one"/>
Option 1, With jQuery and CSS:
$(".one").mouseenter(function() { $(this).css({ "-webkit-transition": "all 1s linear", "width": "50px", "height":"50px" }); }) .mouseleave(function() { $(this).css({ "-webkit-transition": "all 1s linear", "width": "256px", "height":"256px" }); });
With examples about the interaction of CSS and jQuery look here .
Option 2, without CSS:
// increase factor var factor = 2; $('.one').click(function() { $(this).animate({ top: '-=' + $(this).height() / factor, left: '-=' + $(this).width() / factor, width: $(this).width() * factor }); });
Here with examples about animate read.
Ready solution, especially for the author:
HTML
<input type="text" size="40" class="width"> <input type="text" size="40" class="height"> <img src="images/logo/icon-256.png" class="one" />
Jquery:
$(".width").keypress(function(){ $(".one").css({ "-webkit-transition": "all 1s linear", "width":$(this).val(), "height": $(".height").val() }); }); $(".height").keypress(function(){ $(".one").css({ "-webkit-transition": "all 1s linear", "width":$(".width").val(), "height": $(this).val() }); });
Of course, I understand everything, but ready-made solutions lead to laziness, and you yourself know the laziness of what, therefore, I advise you to study everything a little by yourself. And you will not save enough ready answers in programming, even so simple pieces.
.on('keypress', function(){ /* code */ });
? Animation on js is getting rid of itself, css in this regard has become much more powerful, and indeed this is a direct responsibility of css. - user31688I did this (did for Drupal, so jquery might need to be wrapped differently).
html
<img src="#" class="one" />
jquery
(function($) { $(document).ready(function() { $('#edit-submitted-shirina, input').bind('keyUp change', function(){ var wvalue = $('#edit-submitted-shirina').val(); $("#bagbox").attr('width', wvalue); }); $('#edit-submitted-vysota, input').bind('keyUp change', function(){ var hvalue = $('#edit-submitted-vysota').val(); $("#bagbox").attr('height', hvalue); }); }); })(jQuery);
Source: https://ru.stackoverflow.com/questions/403844/
All Articles