| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Senior Member | Javascript question I would like to draw a spiral of words on-screen. Example: I want the word "Hi" to appear in a spiral, multiple times.
__________________ Web Development |
| |
| | #3 (permalink) |
| Senior Member |
__________________ Web Development |
| |
| | #4 (permalink) |
| Buy my domains. | Code: <div id="spiral" style="position: absolute; top: 0; padding-left: 30px;">yo</div>
<script type="text/javascript">
var i = 0;
function spiral() {
document.getElementById('spiral').style.top = (Math.sin(i)*10);
document.getElementById('spiral').style.left = (Math.cos(i)*10);
i += 1;
setTimeout('spiral()',50)
}
window.onload = function () { spiral(); }
</script>
|
| |
| | #5 (permalink) |
| Senior Member | Works. So far. The problem is that I dont want the previous one to disappear when the next one is drawn.
__________________ Web Development |
| |
| | #7 (permalink) |
| Senior Member | Your script makes the dancing word. I dont want it to dance, I want it to create a spiral. In other words, I want the text/images to stay still once it is generated.
__________________ Web Development |
| |
| | #9 (permalink) |
| Senior Member | Im trying to explain this...its a bit difficult to explain. Im sorry if it was phrased wrong before. Your code, shown in action here, has the word 'yo' move around in what appears to be a spiral. However, your code is written so that the actual div moves. What I need is something that can create another <div> with this new positioning, and do that multiple times, so that the word 'yo' does not disappear every time.
__________________ Web Development |
| |
| | #10 (permalink) |
| Senior Member | I think I almost have it ![]() Here is the code I have, the result can be viewed at http://www.domainrealty.info/forum/spiral.html Code: <center><div id="spiral0" style="position: absolute; top: 0; padding-left: 300px; padding-top: 300px;"><div id="contain"></div>yo</div></center>
<script type="text/javascript">
var i = 0;
var divs = new Array();
var x = 0;
function spiral() {
for(x = 0;x <= divs.length;x++) {
document.getElementById('spiral'+x).style.top = (Math.sin(divs[x])*100);
document.getElementById('spiral'+x).style.left = (Math.cos(divs[x])*100);
}
y = x + 1;
document.getElementById('contain').innerHTML += '<div id="spiral'+y+'">yo<\/div>';
document.getElementById('spiral'+y).style.top = (Math.sin(i)*100);
document.getElementById('spiral'+y).style.left = (Math.cos(i)*100);
divs[y] = i;
i += 1;
setTimeout('spiral()',500)
}
window.onload = function () { spiral(); }
</script>
__________________ Web Development |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |