Hello Appery.io team,
I have a HTML/Jquery sample code that resize images proportionally / keeping the aspect ratio (copy from http://stackoverflow.com/questions/39...).
Here is the code that works fine in Standalone html file (outside appery.io plataform). But inside appery.io plataform, this function don ́t work.
code
<img id="story-small" src="http://www.weddingguide.com.br/wp-content/uploads/2013/07/D.Cantidio-3-e1373048601175.jpg" width="280" height="180" >
<script>
$(document).ready(function() {
$('.story-small img').each(function() {
var maxWidth = 100; // Max width for the image
var maxHeight = 100; // Max height for the image
var ratio = 0; // Used for aspect ratio
var width = $(this).width(); // Current image width
var height = $(this).height(); // Current image height
Code: Select all
// Check if the current width is larger than the max
if(width > maxWidth){
ratio = maxWidth / width; // get ratio for scaling image
$(this).css("width", maxWidth); // Set new width
$(this).css("height", height * ratio); // Scale height based on ratio
height = height * ratio; // Reset height to match scaled image
width = width * ratio; // Reset width to match scaled image
}
// Check if current height is larger than max
if(height > maxHeight){
ratio = maxHeight / height; // get ratio for scaling image
$(this).css("height", maxHeight); // Set new height
$(this).css("width", width * ratio); // Scale width based on ratio
width = width * ratio; // Reset width to match scaled image
}
});
});
</script>
/code
In appery.io I already try this, in two ways:
1- using Appery.io image component with ON PAGE LOAD EVENTE Run JAVASCRIPT and change the code
$('.story-small img') TO Appery("myImageName")
2- using Appery HTML component
I need help to understand how to use this function in appery.io, Thanks