Hello - this is going to be really stupid, so bear with me.
I am writing a story where you spend a large amount of time waiting in a queue. The only text on the page is a "wait button". I want the button to move around the page at random so that the user can't just hover on the same spot and mash the mouse to get through it.
I'm having a lot of trouble making it work though - what I think I need to do is get at the CSS and change the top and left margins of the "wait" button at random, which would be totally fine if I knew JS. I know enough JS to generate random numbers, but I don't know how to get those numbers into the CSS, if you know what I mean?
Any tips greatly appreciated, thanks.
Comments
My passage currently looks like this: (I know that's going to loop forever, I'll add a counter and make it end somewhere once I've got this sorted)
And my JS passage currently looks like this: Now whenever I test play I get an error, "Script: document.getElementById(...) is null"
What have I done wrong?
You are, very likely, executing the
document.getElementById()
before the element is on the page. And, if your example code is exactly what you have in ascript
tagged passage, then you're only executing it once at startup anyway. You're also setting the left/top coordinates to raw numbers, which they do not take (valid values are CSS length or percentage data types).Anyway. You're going to need to execute that code every time you go to the
[[Wait]]
passage. Try something like the following: (goes in ascript
tagged passage) You'll also need some styles to make it work properly: (goes in astylesheet
tagged passage)1. Sorry I forgot to post story format. Noob. It's sugarcane.
2. Thanks, it sort of works! The button really likes the top left corner of the page, I'll do some tinkering and see if I can't have it explore the rest of my screen a bit.
3. I probably shouldn't have tried this without learning Javascript fundamentals properly.
Awesome.
Try these instead. The link should now jump around within the entire available passage display area (vertically and horizontally).