Skip to content

Best way to share constants between Javascript & CSS

I’m creating a website with lots of dynamic stuff laid out in javascript, as well as CSS. What’s bothering me is that half of my dimension constants (positions and sizes of things on the page) are in my javascript, whereas others are in my CSS. Is there a good way to have a “single place” for constants like this? First

Create an array with random values

How can I create an array with 40 elements, with random values from 0 to 39 ? Like I tried using solutions from here: http://freewebdesigntutorials.com/javaScriptTutorials/jsArrayObject/randomizeArrayElements.htm but the array I get is very little randomized. It generates a lot of blocks of successive numbers… Answer Here’s a solution that shuffles a list of unique numbers (no repeats, ever). If you want

Define a global variable in a JavaScript function

Is it possible to define a global variable in a JavaScript function? I want use the trailimage variable (declared in the makeObj function) in other functions. <html xmlns="http://www.w3.org/…