jQuery Blockrain.js Plugin
Last Updated :
25 Jul, 2024
jQuery plugins enhance an application with features that would generally take a long time to program correctly. However, some plugins are useful in providing entertainment to users. Although many professional sites may not need these, it is a fun feature to include in personal blogs and websites.
Blockrain.js plugin provides a Tetris game created in HTML5 and JavaScript. Tetris is a famous game and it is one of the famous games people have played and used. Adding this plugin to your website will keep users engaged with your content more.
Blockrain.js not only helps you embed the game but also allows you to customize certain elements such as
- You can change the theme to fit the color scheme of your website.
- You can adjust the speed of the blocks that are falling or as the name goes raining.
- You can choose to add a scoreboard.
- It has an autoplay feature which you can add.
The plugin is available on its website with the same name and it also has a Github repository dedicated to it with documentation.
Note: Before using it, download the files or the zip files and store them to implement in your project.
Download files from link:
https://github.com/Aerolab/blockrain.js
HTML:
The following code demonstrates the basic page structure using HTML tags to show the minimum requirement.
HTML
<!DOCTYPE html>
<html>
<body>
<h1>This is how it appears</h1>
<!-- The div tag below is given
by the plugin developer -->
<div class="game" style=
"width:250px; height:500px;">
</div>
<p><em>
Plugin credits to
https://github.com/Aerolab/blockrain.js
</em></p>
</body>
</html>
Note: For the CSS part, the stylesheet is linked which is provided by the plugin.
jQuery code:
JavaScript
<script>
$game = $('.game').blockrain();
</script>
This involves basic jQuery syntax that involves a selector and the action.
- $ defines that jQuery is used.
- .game is the class of HTML.
Final code:
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="blockrain.css">
<script src=
"https://code.jquery.com/jquery-2.1.4.min.js">
</script>
<script src="blockrain.jquery.min.js"></script>
</head>
<body>
<h1>This is how it appears</h1>
<div class="game" style=
"width:250px; height:500px;">
</div>
<p><em>
Plugin credits to
https://github.com/Aerolab/blockrain.js
</em></p>
<script>
$game = $('.game').blockrain();
</script>
</body>
</html>
Output:
Themes:
We can customize this by adding a theme or whatever they have provided. Let us look at the sample code for that.
The options that are already provided are:
- modern
- retro
- candy
- vim
- gameboy
Many more are also provided.
Let us change the theme to one of these. All you need to do is add one statement to the already existing code:
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="blockrain.css">
<script src=
"https://code.jquery.com/jquery-2.1.4.min.js">
</script>
<script src="blockrain.jquery.min.js">
</script>
</head>
<body>
<h1>This is how it appears</h1>
<div class="game" style=
"width:250px; height:500px;">
</div>
<p><em>
Plugin credits to
https://github.com/Aerolab/blockrain.js
</em></p>
<script>
$game = $('.game').blockrain();
/* This is where you add the line
to change the theme */
$game.blockrain('theme', 'retro');
</script>
</body>
</html>
Output:
gameboy theme
retro themeIt is highly customizable and for websites that would love to add some fun elements, this would be the perfect plugin for it.
Similar Reads
jQuery BlockUI Plugin The BlockUI plugin is used to simulate synchronous AJAX behavior. When activated, it stops the user from interacting with the page until it is deactivated. The DOM (Document Object Model) is added with elements to give a nice user-interface look and feel along with behavior. Download Link: <scrip
2 min read
jQuery CLNDR Plugin jQuery provides a front-end calendar CLNDR plugin using HTML templates mostly used in single-day or multiple days event management system. It is used in appointing dates of various events in the calendar format. You have to download the required files in the working folder so that the programmer can
4 min read
jQuery CLNDR Plugin jQuery provides a front-end calendar CLNDR plugin using HTML templates mostly used in single-day or multiple days event management system. It is used in appointing dates of various events in the calendar format. You have to download the required files in the working folder so that the programmer can
4 min read
jQuery Plugins Introduction Plugins are the section of code and these codes are written in a JavaScript file. These JavaScript files are used to provide jQuery methods that work together with jQuery library methods. You can download jQuery plug-in from https://jquery.com/plugins How to create a jQuery plugin with methods: In J
2 min read
jQuery Slidebar.js Plugin JQuery is a small, fast, rich JavaScript Library that is an optimized version of JavaScript. It provides us with a simple API that helps in HTML document traversal and manipulation, event handling, animation, and Ajax. jQuery provide us with a variety of plugins that can be implemented on the websit
2 min read
jQuery UI Introduction jQuery UI is a curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library. Whether you're building highly interactive web applications, or you just need to add a date picker to a form control, jQuery UI is the perfect choice. Features: jQue
2 min read