DecstarG DecstarG - 1 year ago 121
HTML Question

javscript: How would you make text spin using javascript?

I have this code:

<img src="" id="imgid">
<h1 id='header'>Example</h1>
<!--This is an example html doc not the real thing!-->
<button onclick="spin(document.getElementById('header'));spin(document.getElementById('imgid'));">Spin!</button>
function spin(object) {
setInterval(function() { += "rotate(10deg)";
}, 1);

How do I make the text spin correctly? If you could explain how it works then that would be great. If you need any references of my sources then:

By "correctly" I mean spinning like the image with imgid.

Answer Source

Try this. The main problem was that the width extended all the way across the page which messed up the rotation, so adding in display:inline-block made the width match up with the div's contents.



        <div><img src="" id="imgid"></div>
        <div><h1 id='myDIV'>Example</h1></div>
        <div><button onclick="spin(document.getElementById('imgid'));spin(document.getElementById('myDIV'));">xdfdsf</button></div>

function spin(object)
    { += "rotate(10deg)";
    }, 1);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download