Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dwmkerr/starfield

A nice starfield background using built using HTML and vanilla JavaScript as a learning exercise.
https://github.com/dwmkerr/starfield

html javascript learning space starfield

Last synced: 26 days ago
JSON representation

A nice starfield background using built using HTML and vanilla JavaScript as a learning exercise.

Awesome Lists containing this project

README

        

# Starfield

Starfield is a JavsScript class that displays an animated starfield in a `div` element.

Live Example: https://dwmkerr.github.io/starfield/

[![Starfield Screenshot](./images/starfield.gif "Starfield Screenshot")](https://dwmkerr.github.io/starfield/)

## Quickstart

Create a HTML `div` initialize a `Starfield` like this:

```js
var container = document.getElementById('container');
var starfield = new Starfield();
starfield.initialise(container);
starfield.start();
```

## Full-Code Example

_Ensure starfield.js file is in the same directory as the HTML file._

```html


Starfield

#container {
width: 100%;
height: 100%;
position: absolute;
left: 0px;
top: 0px;
z-index: -1;
}







// Get the container and turn it into a starfield.
var container = document.getElementById('container');
var starfield = new Starfield();
starfield.initialise(container);
starfield.start();

```

## Configuration

You can configure the Starfield by setting the following properties on the class:

```js
var starfield = new Starfield();
starfield.stars = 200; // The number of stars.
starfield.minVelocity = 5; // The minimum star velocity in pixels per second.
starfield.maxVelocity = 15; // The maximum star velocity in pixels per second.
```

## Learning More

This code was created for **[Create a Starfield](codeproject.com/Articles/642499/Learn-JavaScript-Part-1-Create-a-Starfield)**, the first article of my _Learn JavaScript_ series on CodeProject.