Arnolds Kļavenieks
Arnolds Kļavenieks

Reputation: 67

jQuery rotate cube when the button is clicked

Why doesn't button make cube rotate?
I am adding +=45deg to it! Here's the code: jQuery:

$(document).ready(function(){
    $('button').click(function(){
        $('#cube').css('-webkit-transform','rotateY(+=45deg)');
    });
});

Html:

<button>rotate</button>
<div id="cube">
</div>

css:

#cube {
display: block;
width: 250px;
height: 250px;
background: #66F;
}

jsfiddle: http://jsfiddle.net/ysLet/

Upvotes: 1

Views: 1310

Answers (1)

Raffael
Raffael

Reputation: 810

http://jsfiddle.net/ysLet/3/

seems like the += operator does not work in the css line

    $(document).ready(function(){
    deg = 0;
    $('button').click(function(){
        deg += 45;
        $('#cube').css('-webkit-transform','rotateY('+deg+'deg)');
    });
});

this did the trick...

Upvotes: 2

Related Questions