Randomization Clickthrough Widget
Certain pages on this site, and others I’ve made, feature a cute little random clickthrough widget of sorts. In these setups, the user can click a button to randomly load a statement from a predefined series using HTML, CSS, and Javascript. This isn’t exactly useful as such, but is interesting, creative, and fascinating for visitors. I wanted to share the (rather simple, in fact) code here just in case anyone else wants it.
I provide both a stripped-down version featuring just the basic areas necessary for the features to work, and a more aesthetically-aligned version. The latter is actually pretty easy to customize, in my opinion. I’m trying to give proper documentation to allow you to do that (with both of them, actually).
View a live preview of both versions on on Codepen, along with all three necessary code components.
You can use the aesthetic version (with any modifications necessary) as you’d like, or use the plain version with an existing theme. I’ve also found that some sites provide small frames work well with these, if you simply place the plain version inside with a few tweaks to the CSS.
Orange Cat Version
While many of the demonstrative pages on this site are garden or floral-themed, this one focuses on an orange tabby cat, and you’ll have noticed if you visit it on Codepen. I have done this because I feel that orange tabby cats are significantly undervalued, especially the male tabby cats (and most orange tabbies are, in fact, I am told, male).
They are often called stupid or ridiculous, and that’s an unfair stereotype since I’ve known many pleasant and intelligent orange tabbies. In any case, this demonstration is aggressively orange, and I hope you enjoy it. You can very easily alter the CSS (more on that later) so that it isn’t orange, of course.
CSS
This version of the form, which is meant to be a decent start to aestheticizing the experience, features an orange theme, but all colors and features can, of course, be changed. Much of the styling relies on the container #dreamwindow and the button within it, and you can edit both readily.
There is also #dreamed, which allows you to style the output itself - the randomized statements that appear. Please note that this also includes styling for a title tag, because why not? You can always remove it! View this version (and any recent changes to it not yet reflected on this page) live on Codepen.
HTML
Most of what I’ve added here are containers for aesthetic purposes. Only the button itself and the paragraph with the ID #dreamed are really necessary to make the widget itself functional. Obviously, title text (if you want to include the <h1> tag at all, for example) or any other additions are possible, too. Do not put anything directly within the HTML of the paragraph labeled #dreamed or it will vanish when the Javascript takes hold…
Javascript
The Javascript fills the paragraph called #dreamed with the randomized statements. In the case of the example we’re using below, it is populated here (and on Codepen) with eight autobiographical facts about a small orange cat, typical of most orange cats. You can add any number of these, though, simply by following the same syntax (within backticks followed by a comma) and adding some at the end.
Plain Version HTML
This version uses the same Javascript as above, but is without any lavish CSS customizations.