Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate text at button click event

Tags:

javascript

css

I need to rotate a text at different angles at button click.

I need two button, one to move text clockwise and other to move text anticlockwise.

like image 743
Chauhan Avatar asked Nov 17 '10 07:11

Chauhan


People also ask

How to rotate 180 degrees CSS?

Rotating an image using CSS Once the CSS code is applied to your . css file, stylesheet, or <style> tags, you can use the CSS class name in any of your image tags. To rotate an image by another measure of degrees, change the "180" in the CSS code and <img> tag to the degree you desire.

How to rotate text in word?

Do one of the following steps: Select the text box, and then go to Shape Format or Drawing Tools Format > Rotate. Use any of the rotate commands in the list. Manually rotate the text box by selecting the text box rotation handle and dragging in the direction you want.

How to rotate button in CSS?

You can check it out there, or at the CodePen below. To trigger the transition effect we have to add an onclick event attribute to each button. This fires off a bit of JavaScript that applies an active class to the button. With this class the can then rotate the button with transform: rotate(45deg) .


1 Answers

try this:

html:

<input id="rotateBtn" type="submit" value="rotate"/>
<div class="textToRotate">text to be rotated</div>

css ( tip: use transform-origin to control rotation anchor point, here used only for webkit )

.rotate {
-moz-transform: rotate(7.5deg);  /* FF3.5+ */
 -o-transform: rotate(7.5deg);  /* Opera 10.5 */
 -webkit-transform: rotate(7.5deg);  /* Saf3.1+, Chrome */
 -webkit-transform-origin: 0 0 ;
 filter:  progid:DXImageTransform.Microsoft.BasicImage(rotation=0.083);  /*IE6,IE7 */
 -ms-filter: "progid:DXImageTransform.Microsoft.BasicImage(rotation=0.083)";  /* IE8 */
 }

jQuery on document ready:

 $('#rotateBtn').click(function() {
     $('.textToRotate').addClass('rotate');
 });

check it out here: http://jsfiddle.net/SebastianPataneMasuelli/YZY8J/2/


update: each click increments 20degrees: http://jsfiddle.net/SebastianPataneMasuelli/YZY8J/5/

like image 167
Sebastian Patane Masuelli Avatar answered Nov 10 '22 15:11

Sebastian Patane Masuelli