Rotate image while maintaining aspect ratio

Asked

Viewed 1,130 times

3

I need to rotate an image and maintain the ratio relative to the parent DIV without 'escaping'. I’m just using rotate(90deg) and the original image properties, as in the example.

There are some plugins that do this but contain a lot of unnecessary stuff, I believe some adjustment in CSS solve, but not the attributes to manipulate images like this.

$('button').click( function( event )
{
	$('img').css({ transform : 'rotate(90deg)' })
})
div{border:#000000 solid 1px; width:200px; height:300px; text-align:center}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>girar</button>

<div>
<img src="http://i.ebayimg.com/images/g/v7sAAOSwQTVV7toe/s-l300.jpg">
</div>

  • Any problem solving this with javascript?

  • @Samirbraga, any suggestions?

  • Papacharlie, yes I do, take a look at this Jsfiddle I prepared, if it fits, let me know... https://jsfiddle.net/qub8gLp6/1/

  • @Samirbraga, using a larger image does not align to the top, I kept its code, only changed the image: https://jsfiddle.net/d56ynd12/

  • I looked at what I said and I was able to solve, with one more thing in javascript, nothing very complex, just some css properties.. https://jsfiddle.net/qub8gLp6/4/. Have a look.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.