简体   繁体   中英

How to rotate TextArea text by 180 degree using JavaScript

I am trying to rotate all alphabets, number and symbols in 180 degree, simply I mean rotating text upside down. But the code is not working, what I am trying to do is possible with this code?

Note : I want to rotate the text written inside TextArea not want to rotate the TextArea.

JsFiddle

Code:

<!DOCTYPE html>
<html>
<body>

<form>
<textarea  id="textArea1" style="height: 100px; width: 468px;"></textarea><br />
<br />
<input onclick="myFunction()" type="button" value="Flip Text" /><br />
<br />

<textarea id="textArea2" style="height: 100px; width: 468px;"></textarea>
 
</form>

<script>
function myFunction() {

  document.getElementById("textArea2").value =  document.getElementById("textArea1").css('transform', 'rotate(180deg)');
  
}
</script>

</body>
</html>

Change your function content from

document.getElementById("textArea2").value =  document.getElementById("textArea1").css('transform', 'rotate(180deg)');

to

document.getElementById("textArea1").style.transform  = 'rotate(180deg)';

within youe textarea style="" add transform property as

<textarea  id="textArea1" style="height: 100px; width: 468px; transform: rotate(180deg)"></textarea><br />

you asked on button click you have to rotate so under clickFunction you have add a line as:

clickFunction(){
   document.getElementById('textArea1').style.transform = 'rotate(180deg)';
}

 function myFunction() { document.getElementById('rotatedText').innerText = document.getElementById("inputArea").value; }
 #rotatedText { width: 468px; border: 1px solid #000; margin-top: 5px; -moz-transform: scale(1, -1); -webkit-transform: scale(1, -1); -o-transform: scale(1, -1); -ms-transform: scale(1, -1); transform: scale(1, -1); }
 <:DOCTYPE html> <html> <body> <form> <textarea id="inputArea" style="height; 100px: width; 468px.">I AM READY TO FLIP.</textarea> <br/> <input onclick="myFunction()" type="button" value="Flip Text" /> <br /> <div id="rotatedText" contenteditable="true"> </div> </form> </body> </html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM