We now have a youtube channel. Subscribe!

jQuery Blockrain.js Plugin



Hello dear readers! Welcome back to another edition of our tutorial on jQuery. In this tutorial guide, we are going to be discussing about the jQuery Blockrain.js plugin.

Blockrain.js is a plugin that allows you to embed the classic Tetris on your website.

Example

The following below is a simple Blockrain.js example -

<!DOCTYPE  html> 
<html> 
     <head> 
          <meta  charset =  "utf-8" /> 
          <link   href = ' https://fonts.googleapis.com/css?family=Play:400,700' 
               rel  = 'stylesheet'   type = 'text/css'> 
          <link  rel = "stylesheet"   href = "assets/css/style.css"> 
          <link  rel = "stylesheet"   href = "src/blockrain.css"> 
     </head> 

     <body> 

          <section   id =  "examples"> 
               <article   id =  "example-slider"> 

                    <div   class =  "example"> 
                         <div class = "instructions"> 
                              Use only arrows 
                              <div   class =  "keyboard"> 
                                   <div  class = "key key-up"></div> 
                                   <div  class = "key key-left"></div> 
                                   <div  class = "key key-down"></div> 
                                   <div  class = "key key-right"></div> 
                              </div> 
                         </div> 

                         <div   class =  "game"   id = "tetris-demo"></div> 
                    </div> 

               </article> 
          </section> 

          <script   src =   "assets/js/jquery-1.11.1.min.js"></script> 
          <script   src =   "src/blockrain.jquery.libs.js"></script> 
          <script   src =   "src/blockrain.jquery.src.js"></script> 
          <script   src =   "src/blockrain.jquery.themes.js"></script> 

          <script> 
               var  $cover =  $'#cover-tetris' ).blockrain( { 
                    autoplay:   true, 
                    autoplayRestart:  true, 
                    speed:  80, 
                    autoBlockWidth:  true, 
                    autoBlockSize:  25, 
                    theme:  'candy' 
               } ); 
               var  versusSpeed =  300; 
               var   $versus1  =  $'#tetris-versus-1 .game' ).blockrain( { 
                    autoplay:   true, 
                    autoplayRestart:   true, 
                    speed:   versusSpeed, 

                    onGameOver:    function( )  { 
                         $versus1.blockrain'restart' ); 
                         $versus2.blockrain'restart' ); 
                         var  $score =  $versus2.parent( ).find'.score' ); 
                         $score.text( parseInt$score.text( ) ) + 1 );
                    } 
               } ); 
               var   $versus2 = $'#tetris-versus-2 .game' ).blockrain( { 
                    autoplay:   true, 
                    autoplayRestart:   true, 
                    speed:  versusSpeed, 

                    onGameOver:   function( )  { 
                         $versus1.blockrain'restart' ); 
                         $versus2.blockrain'restart' ); 
                         var  $score =  $versus1.parent( ).find('.score'); 
                         $score.text( parseInt$score.text( ) ) + 1 ); 
                    } 
               } ); 
               var   $demo =  $'#tetris-demo' ).blockrain( { 
                    speed:  30, 
                    theme: 'black', 

                    onStart:   function( ) { 
                         ga( 'send',  'event',  'tetris',  'started' ); 
                    }, 
                    onLine:  function( ) { 
                         ga( 'send',  'event',  'tetris',  'line'); 
                    }, 
                    onGameOver:   functionscore )  { 
                         ga( 'send',  'event',  'tetris',  'over',  score); 
                    } 
               } ); 

               $'#example-slider' ).find'.btn-next' ).clickfunctionevent ) { 
                    event.preventDefault( ); 
                    switchDemoThemetrue ); 
               } ); 
               $'#example-slider' ).find'.btn-prev' ).clickfunctionevent )  { 
                    event.preventDefault( ); 
                    switchDemoThemefalse ); 
               } ); 

               function   switchDemoThemenext )  { 
                    var  themes =  Object.keysBlockrainThemes ); 
                    var  currentTheme =  $demo.blockrain'theme' ); 
                    var  currentIx =  themes.indexOf(currentTheme); 

                    if  ( next ) { currentIx++; } 
                    else { currentIx--; } 

                    if ( currentIx > = themes.length ){ currentIx = 0; } 
                    if( currentIx < 0 ){ currentIx = themes.length-1; } 

                    $demo.blockrain'theme',  themescurrentIx ] ); 
                    $'#example-slider .theme strong' ).text( ' " ' themes[currentIx] + ' " ' ); 
               } 
          </script> 

     </body> 
</html>


Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial guide, we are going to be discussing about the Producttour.js Plugin.

Do feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain