JavaScript Rotate image every time on click JQuery

This can easily be done by using just javascript, working example would be like this

<div id="imgWrapper">
    <img src="Desert.jpg" id="image" onclick="rotateBy10Deg(this)">  
</div>

<script>
    var delta =0;
    function rotateBy10Deg(ele){
        ele.style.webkitTransform="rotate("+delta+"deg)";
        delta+=10;
    }
</script>
Answer:1

The plugin converts the img into a canvas, that's the reason the click not working for second time. Change your jQuery or refer this demo

$(document).ready(function() {
  $("img").click(function() {
    $(this).rotate(45);
  });
  $('body').on('click', 'canvas', function() {
    $(this).rotate(45);
  });
});
Answer:2

I suggest setting max-height and max-width in your CSS file. This will ensure the image doesn't exceed a certain size.

Answer:3

This link might help you out:

Rotate image with onclick

Taken straight from that link in case you don't want to click:

Javascipt

var rotate_factor = 0;

function rotateMe(e) {
    rotate_factor += 1;
    var rotate_angle = (180 * rotate_factor) % 360;
    $(e).rotate({angle:rotate_angle});
}

HTML

<img src='blue_down_arrow.png' onclick='rotateMe(this);' /></a>
Answer:4

I think the angle (45 degree) is calculated in reference to its initial angle that is 0. Once the image is in 45 degree it will only have to rotate if the angle changes (eg 90). So the below code may work

$(document).ready(function () {
 var angle = 0;
$("img").click(function () {
      angle = angle+45;
  $(this).rotate(angle); 
})
})
Answer:5

I am trying to call a JavaScript function from the onclick event of two different buttons. I have dug around and searched for like problems but have not found a solutions. When I click either button I ...

I am trying to call a JavaScript function from the onclick event of two different buttons. I have dug around and searched for like problems but have not found a solutions. When I click either button I ...

  1. unable to call function in ajax success
  2. unable to call function dllinstall
  3. unable to call javascript function from html
  4. unable to call the function dllinstall in the file browseui.dll
  5. unable to call javascript function from code behind
  6. powershell unable to call function
  7. unable to call javascript function
  8. unable to call the function dllinstall in the file webcheck.dll

So I'm trying to get the width of the element using jQuery. alert($("#theList li:eq(0)").offsetWidth); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></...

So I'm trying to get the width of the element using jQuery. alert($("#theList li:eq(0)").offsetWidth); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></...

I have a situation where I have 3 components; <View> <Content> and <Footer>. <View> is parent of <Content> and <Footer>. Now there is a button in <Footer> ...

I have a situation where I have 3 components; <View> <Content> and <Footer>. <View> is parent of <Content> and <Footer>. Now there is a button in <Footer> ...

  1. reactjs accessing child state
  2. react accessing refs

I build my page with angularJS. When I test it every thing works well, but sometimes the page flickers. Here is a sample when I click M1 > Sub-Menu-Item, I see the page flicker. Can anybody help ...

I build my page with angularJS. When I test it every thing works well, but sometimes the page flickers. Here is a sample when I click M1 > Sub-Menu-Item, I see the page flicker. Can anybody help ...