Home & blog  /  Scripts  /  view post  /

Blockster transition effect

Overview

Blockster is a Javascript transition effect designed for 'featured content' rotators or slideshows. Its underlying concept is to transition between one element to the next block by block. It is highly customisable in terms of how many blocks are involved, whether they fade in or simply appear, whether they appear in order or randomly, and more.

Example 1

Mitya likes jQuery

Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah - read more

Mitya likes GD

Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah - read more

Mitya likes Mootools

Blah blah blah blah blah blah blah blah blah blah - read more

Here we opt for 4 rows and 6 columns, with the blocks fading in randomly, not in order. Here's the code behind this example:

1var blocksterInstance = new Blockster({

2     holder: '#featureRotator_1',

3     rows: 4,

4     cols: 6,

5     random: true

6});

Usage & params

HTML & CSS

Simply ensure you have a holder

and, inside, a
for each slide. Enusure the holder and the slides have the same fixed dimensions - don't give your slides width/height 100%. The holder should be set to position 'relative' and the slides position 'absolute'. The HTML/CSS behind the examples on this page is included in the source .ZIP.

Javascript

Call blockster(params), where 'params' is an object of property/value pairings from the following:

holder (string, default: null) - a string to be used as a jQuery selector pointing to the holder element that contains the slides

rows (int, default: 10) - the number of rows for the block grid

cols (int, default: 10) - the number of columns for the block grid

pause (int, default: 3500) - the number of miliseconds to wait (i.e. show the slides) between transitions

animType (string, default: 'fade') - either 'simple' or 'fade'. If the former, blocks simply appear. If 'fade', they fade in.

random (bool, default: false) - if true, blocks will appear/fade-in in random order

blockAnimSpeed (int, default: 50) - the number of miliseconds between each block appearing/fading in

startWithoutDelay (bool, default: false) - to avoid the initial delay, and have the first transition happen immediately, pass this as true

runOnceOnly (bool, default: false) - to terminate the script after the first transition, pass this as true

See the two examples on this page for demo code.

Controlling with navigation

As of 16 September 2010, Blockster is now controllable with navigation, meaning you can employ it not so much as a slides rotator but as a carousel (though if you want a carousel, check this out).

To do this, have your links or code call the jump() method, like so:

1blocksterInstance.jump(0); //go to slide 1

2blocksterInstance.jump(3); //go to slide 4, etc

...where blocksterInstance is the variable that holds the instance of Blockster you are targeting (see code in examples).

Non-slideshow use

Blockster can be used as a one-off effect to initially shield then reveal content. To do this, your shield would be the first

  • and your content would be your second. Then, instantiate Blockster with both the runOnlyOnce and startWithoutDelay arguments set to true.

    Example 2

    Mitya likes jQuery

    Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah - read more

    Mitya likes GD

    Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah - read more

    Mitya likes Mootools

    Blah blah blah blah blah blah blah blah blah blah - read more

    Here we've chosen 2 rows and 15 columns, with each block fading in in order. Here's the code behind this example:

    1var blocksterInstance2 = new Blockster({

    2     holder: '#featureRotator_2',

    3     rows: 2,

    4     cols: 15

    5});

    Notes

    Dependent HTML/CSS

    Blockster places a few basic requirements on the HTML and CSS applied to your rotator or slideshow. See above (usage and params) for more info. The HTML/CSS behind the examples on this page is included in the source .ZIP.

    How?

    That would be telling, but it has nothing to do with background positioning. So you can safely load your slides with child elements - links, paragraphs, images, whatever - and it will still work fine.

    Update: controlling with navigation

    As of 16th September 2010 Blockster is now controllable with navigation. More info over here and related blog post over here.

    Update: Blockster for non-slideshow use

    As of 30/01/2010 Blockster can be used as a means to shield then reveal content, rather than as a slideshow tool. See above for info on this.

    Loading jQuery

    By default, this script assumes you're loading jQuery via Google (why might you do this?). If, instead, you're loading jQuery from a local copy in your site folder, update the document ready handler (DRH) in the script file:

    1//loading jQuery via Google

    2google.setonloadcallback(function() { ...

    3 

    4//loading jQuery from local copy (use either)

    5$(document).ready(function() {...

    6$(function() {...

    post new comment

    Comments (67)

    Martin, at 13/09/'10 11:28, said:
    Hi,
    
    just a question. If this is relying on jQuery why don't implement it as a jQuery plugin?
    Mitya, at 13/09/'10 11:43, said:
    Hi Martin. It's a misconception that everything in jQuery needs to be a plugin. A plugin suggests tangibility, i.e. the script can run on any - or at least many - elements passed in the selector string. Blockster, though, can run only on the dependent UL that holds the slides. I decided to specify that UL in the function arguments rather than as a selector string. Same result.
    Paul, at 14/09/'10 18:44, said:
    Is it possible to change the pause value after the script has loaded?
    Mitya, at 14/09/'10 19:42, said:
    Paul - yes, see the 'pause' parameter above.
    MarcJ, at 15/09/'10 04:34, said:
    Very nice effect. Thanks for the script. I notice the the java engine stays busy even when paused. Is there a better jquery wait function or something that could be used? Sorry if this is a silly question, I am a jquery and javascript novice. 
    Mitya, at 15/09/'10 09:58, said:
    Hi Marc. The JS engine continues running throughout the effect because of the interval that times when to start the next transition. This is unavoidable. JS wasn't designed for animation - it only simulates it with intervals - and, as such, effects like Blockster don't perform well in legacy browsers like IE6. Modern browsers like Opera have super-fast JS engines, though, so they cope fine.
    Eric, at 20/09/'10 15:35, said:
    Hello.
    First off, awesome work!
    Quick question though. Once it reaches the last slide, my slideshow fails to go back to the first slide and loop. Am I missing something or is this functionality not in place? 
    Thanks!
    Eric
    Mitya, at 20/09/'10 15:38, said:
    Hey Eric - thanks :) No it should loop. The ones on this page do (at least in the browsers I've tested in). What browser are you in, and do you get a JS error in the console?
    Eric, at 20/09/'10 16:36, said:
    I'm using the latest version of Firefox.
    I'm getting this error:
    Error: this.params.holder.children("div").first is not a function
    Source File: http://flywheeldesign.com/mla/scripts/blockster.js' target='_blank'>http://flywheeldesign.com/mla/scripts/blockster.js
    Line: 79
    
    And this recurring warning:
    Error: this.params.holder.children("div").first is not a function
    Source File: http://flywheeldesign.com/mla/scripts/blockster.js' target='_blank'>http://flywheeldesign.com/mla/scripts/blockster.js
    Line: 79
    Mitya, at 20/09/'10 16:44, said:
    I too have the latest FF and it works fine for me. No errors and it loops. Do the examples on this page work for you? If so, it must be something to do with your implementation. Post a URL?
    
    BTW, I noticed on your site that the navigation drop-downs don't work in Opera (that may or may not concern you).
    Eric, at 20/09/'10 16:54, said:
    Strange, the examples do work on this page. Here is the URL to the page I'm working on. The background has the transitions. 
    http://flywheeldesign.com/mla/about.php
    Mitya, at 20/09/'10 17:03, said:
    Weird - there's definitely some issue in the version on your site; I'm getting the error in Opera, too.
    
    Are you using my latest code? It looks like you are, just checking.
    
    Try disabling any other scripts you've got going on. If it continues, let me know and I'll try to replicate the error my end with a view to fixing it.
    Eric, at 20/09/'10 17:11, said:
    Ha! Disregard everything. You're code is perfectly fine. I was running an older version of jQuery (1.3.2). Just linked up to 1.4.2. and it works like a charm. Thanks for all the help though and again for the great code!
    MarcJ, at 22/09/'10 04:25, said:
    Hi Mitya,
    Again, thanks for this effect. I have had problems with it in IE, even visiting your page. Both in IE8 normal and compatibility mode.  While I prefer Chome, IE needs to work too. Thanks!
    Mitya, at 22/09/'10 14:05, said:
    Marc - it works for me in both IE7 and IE7. Strange. Do you get a particular error with the demos on my page?
    MarcJ, at 22/09/'10 17:05, said:
    Mitya - The symptom is that the IE8 slows down and eventually I get the 'A script on this page is causing Internet Explorer to run slowly' message. I have tested it on a few machines, win7 and vista.
    Mitya, at 22/09/'10 17:09, said:
    Unfortunately, without some major re-write, there's not a great deal I can do about this. The point is, IE - even IE8 - has a vastly slower JS engine than, say, Opera or Chrome. This, coupled with the fact that JS was never built for animation or CPU-heavy effects like this, is causing the problem. What I would do is conditionalise the animType param so it's set to 'simple' (i.e. no fading) for IE and 'fade' for others. This might help the situation.
    wade, at 24/09/'10 06:50, said:
    That's very nice effect! Have you seen the iPad foto app transform effects? can you do that?
    Mitya, at 24/09/'10 09:52, said:
    Thanks, Wade. I don't know the effect you speak of; is there a YouTube vid showing it or something?
    RickyD, at 7/10/'10 15:24, said:
    Thank You for the script. It works really well. I have a question: Is there a way to do a callback or function after each slide?
    , at 7/10/'10 15:36, said:
    Glad you like my script, RickyD. There is currently no way to stipulate callback at the point of instantiation. You can hard code this in by calling your callback from within the elseif block that starts on line 147 in the script.
    
    Feel free to extend my code to accept a callback as an argument at the point of instantiation. So for example:
    
    var blocksterInstance = new Blockster({
           /* params etc */,
           callback: function() { alert('hello, mum'); }
    });
    
    Then inside the esleif condition on line 147, put:
    
    if (thiss.params.callback && typeof thiss.params.callback == 'function') thiss.params.callback();
    Matt, at 16/10/'10 02:30, said:
    Very Nice. One request / question... Is there a way to make it process the row then the column... Currently it is left to right, top to bottom.... could it instead be top to bottom, left to right? 
    Mark, at 20/10/'10 12:22, said:
    Great plugin, good to see a change from the sliders that are now everywhere.
    
    Though I have noticed change with the newer release of jQuery 1.4.3 the 1st block is repeated for the entire image instead of the image been broken up
    
    (1.4.2 work fine)
    Mitya, at 20/10/'10 12:50, said:
    Thanks for bringing this to my attention, Mark. How annoying is that? Thanks, jQuery! I think I can guess what the problem is, shouldn't be too hard to fix.
    Mitya, at 20/10/'10 12:50, said:
    Matt - currently, no, but it's a feature I might add, come to think of it.
    gladwin, at 21/10/'10 21:25, said:
    hi Mitya,
    this script dont work with ie8. getting the below error :
    
    Webpage error details
    
    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2)
    Timestamp: Thu, 21 Oct 2010 20:23:42 UTC
    
    
    Message: 'events' is null or not an object
    Line: 113
    Char: 467
    Code: 0
    URI: http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js' target='_blank'>http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
    
    
    Message: 'events' is null or not an object
    Line: 113
    Char: 467
    Code: 0
    URI: http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js' target='_blank'>http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
    
    
    mitya, at 21/10/'10 21:56, said:
    Hmm, odd. Never noticed that before. It works on my local machine in IE8, but not on my site. Yet it's exactly the same files. I'll look into this - thanks.
    Mark, at 26/10/'10 10:31, said:
    Hi Gladwin, Mitya
    
    I too have got that error in IE8 for some reason.
    
    Found a temporary fix, if you use jQuery V1.4.1 you don't get the annoying script warning after every transition.
    
    
    " target="_blank">http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js">
    
    
    hope this helps
    
    Mitya, at 27/10/'10 12:58, said:
    Hi Mark - thanks for that. I haven't been able to pin down what causes that IE error yet. But yes, as you say, using 1.4.1 seems to solve this, and that is still a sufficiently recent release of jQ.
    Mitya, at 27/10/'10 13:20, said:
    FIX FIX FIX - I've worked out what was causing the problem. Seems to be a bug in jQ 1.4.3; for some reason, when the CSS values were being set (which were perfectly valid), reading them back produced 0 (zero) every time. So I fudged it by setting some variables and reading those instead. I have uploaded the new and working source code.
    Mark, at 28/10/'10 16:58, said:
    nice one, I'm using 1.4.3 on IE8 and all is well
    Gale, at 4/11/'10 14:52, said:
    Mitya,
    This script is exceptionally beautiful!
    The only problem that I have - in my case it doesn't work in Safari or IE7. FireFox is OK.
    Can you suggest something?
    Mitya, at 4/11/'10 15:56, said:
    Hi gale. It works for me in IE7. Can you post a link to your implementation? Does it work for you on my page?
    Gale, at 7/11/'10 00:18, said:
    It works now! I tested in IE 7, FireFox and Safari.
    I don't know what was wrong. I re-installed all JS scripts again and it started to work again. I use the script I downloaded from this site about a month ago.
    Here is the link:
    http://www.hipstyleandvalue.com/miami-colors/miami-colors.html
    I am still testing. I use 5 images, 400px by 400px; 1p rows and 10 columns. 
    From your site it always worked in IE7, FF and Safari.
     
    
     
    Mitya, at 7/11/'10 12:41, said:
    Good stuff.
    exiang, at 9/12/'10 06:09, said:
    I have added the following features to this great plugin and would like to contribute back:
    
    - able to slide left/right and top/down on top of the current fade in/out and show/hide
    - able to get the current displaying slide index
    
    Download
    www.yeesiang.com/tmp/blockster.zip
    James, at 9/12/'10 17:55, said:
    Hi Mitya. I have setup blockster with some modifications to the CSS & it works fine on FF, CHROME, SAFARI, OPERA, IE9, IE8, but NOT IE 7, its almost as if the js isn't even being run, it stays on the opening slide. Very strange...
    
    http://chromausa.com
    Mitya, at 9/12/'10 19:30, said:
    Exiang - that's great, thanks for that. Could you document it, though, i.e. how to use the changes you've implemented? E-mail this to me then I'll feature your work on the homepage in a blog post. Thanks again.
    
    James - remove the trailing comma you've got after 'pause: 8000' in your instantiation code and IE will be happy.
    James, at 9/12/'10 23:26, said:
    Exiang - Seriously, I feel pretty dumb right now... a comma. Thank you very much, it works as expected.
    Dallas, at 22/01/'11 21:35, said:
    Does not appear to work in Chrome 8.0.552.231
    Kelly, at 26/01/'11 17:04, said:
    Is there a way to adjust when the transitions start from the time the page loads? I'd like the transitioning (block flips) to happen immediately once page is loaded and can't seem to make that happen by adjusting pause or blockAnimSpeed. Is it possible?
    Mitya, at 26/01/'11 17:19, said:
    So you want to avoid the initial delay, i.e. transition immediately, but then pause between slides as normal thereafter?
    Kelly, at 26/01/'11 18:17, said:
    yes. exactly. Avoid the initial delay.
    Kelly, at 26/01/'11 23:37, said:
    This web page is a work in progress. I'm 'playing' with your script to create an interesting homepage graphic. However, I utilized FancyBox too (http://fancybox.net/) and the transition 'eats away' the fancybox pop-up too. It didn't do it on IE on PC's (go figure) but it does do it in Firefox and all browsers on a Mac. Any ideas? Thank you.
    Kelly, at 26/01/'11 23:50, said:
    Ahhh, sorry about that, but maybe this thread is helpful to someone else. The z-index in the blockster.js was 10000 in FancyBox the Z-index in CSS aas set to 1000 and 1001 - I simply changed the zindex in the blockster.js to 999 and it works in all browsers.
    Chris, at 27/01/'11 16:41, said:
    Hey Mitya, nice script.
    
    Is there an easy way to kill the script once the final slide in the sequence has loaded? 
    
    Everything I have tried stops the visual rotation, but the script continues throwing an error when it get to the nextSlide_clone var set.
    
    Thanks
    Mitya, at 30/01/'11 16:01, said:
    Kelly - you can now add a new parameter, "startWithoutDelay". Pass this as true to avoid the initial delay.
    
    Chris - you can now add a new parameter, "runOnlyOnce". Pass this as true and the script will terminate after the first transition.
    Nick, at 31/01/'11 21:51, said:
    Here's how I solve the script error in IE7 Hope works on other IE's
    
    
    -> you can still use 1.4.2 or guess 1.4.3 for other purpose..
    
    Just Try Using 1.4.1:
    
    
    
    Notice.. I used 
    
    Patrice, at 1/02/'11 15:59, said:
    Is there a way that we can use your blockbuster with jquery cycle all slideshow plugin... 
    
    Thanks
    Chris, at 1/02/'11 17:01, said:
    Awesome, thanks!
    
    Just an FYI, the param in the script is 'runOnceOnly', you have 'runOnlyOnce' in your comment and in the change log. 
    Mitya, at 1/02/'11 19:16, said:
    Patrice - possibly, but I don't know that plugin so I don't know.
    
    Chris - well spotted, thanks.
    Brian, at 9/02/'11 20:07, said:
    Implementation at cjmillerart/
    
    I'm loading the images multiple times to give the appearance of a longer delay between the actual pictures and the white space image.   Still having problems in IE, even after changing back to jQuery 1.4.1.   Ideas??
    Brian, at 11/02/'11 03:51, said:
    Maybe a fix... I changed the DocType declaration to strict instead of transitional.. it seems to have corrected the problem. I'll report back after testing on a few different computers.
    Cristian, at 23/02/'11 19:28, said:
    Hey,
    I'm trying to use the runOnlyOnce parameter, but seems like it doesn't work. I've checked the source code and I don't see any mention of runOnlyOnce parameter. May I've downloaded an old version?
    The script works awesome! Thanks for your hard work.
    Andrea, at 24/02/'11 18:44, said:
    Hi. 
    - Any news about the heavyness on IE 7 and 8? The idea of a conditional animType depending on the browser (simple on IE and fade on others) is still in progress?
    - The param runOnlyOnce seems not work on any browser. 
    
    Thanks 4 your work.
    Chris, at 25/02/'11 16:54, said:
     - the correct parameter is 'runOnceOnly', not 'runOnlyOnce'.
    Mitya, at 26/02/'11 13:41, said:
     & Christian: Chris is correct, the parameter is runOnceOnly. Sorry for the confusion (I got it wrong in the arguments list, now ammended).
    
     - re: heaviness in IE, I recently modified it for a client whereby the fade animation was removed completely and the number of blocks was reduced to 4. I would suggest this sort of conditional approach, based on browser detection.
    Scott, at 13/03/'11 16:00, said:
    Fantastic script. I was wondering if there's a way to pause the script when a user mouses over, and resume on mouse out?
    
    Cheers!
    Mitya, at 23/03/'11 12:01, said:
    : presently, no, but this could quite easily be implemented by adding mouseenter and mouseleave events. On mouseenter, a global variable would be set, something like "isHover = true". Then, in the interval which keeps the thing looping, it would return (i.e. not execute) if that variable was set. The corresponding onmouseleave event would set te variable to false, hence the cycle would continue. I might implement that myself when I get time.
    PC, at 18/04/'11 05:27, said:
    Great work! Just wanted to let you know I ran into a small issue with the jump() method on jQuery 1.5.2. Whenever jump(0) was called, Blockster would iterate to the next image in the set rather than jumping back to the first image. In order to fix this, I changed the following in the main function from:
    
    var nextSlide = !indexOfSlideToTurnOn ? currentSlide.nextAll().length != 0 ? currentSlide.next() : this.params.holder.children('div').first() : this.params.holder.children('div').eq(indexOfSlideToTurnOn);
    
    To:
    
    var nextSlide = indexOfSlideToTurnOn >= 0 ? this.params.holder.children('div').eq(indexOfSlideToTurnOn) : currentSlide.nextAll().length != 0 ? currentSlide.next() : this.params.holder.children('div').first();
    James, at 20/07/'11 11:03, said:
    Sweet script! I was going to use this for a project but when I started to add the jump navigation I couldn't figure out how to make the current navigation change with the slides. Any pointers on how to do this would be much appreciated!
    Ljubimci, at 22/09/'11 20:57, said:
    Great post, thanks for sharing!!!
    Sergey, at 19/10/'11 12:29, said:
    line 155 $('.block:animated') and line 159              $('.block').remove() - all .block on my page removed :^)
    Mitya, at 19/10/'11 14:38, said:
     - sorry, don't understand what you mean.
    Mitya, at 19/10/'11 14:40, said:
    @PC - thanks. Was this unique to 1.5.2, do you know?
    Teresa, at 13/06/'12 20:29, said:
    Is there a way to terminate the script after a chosen number of transitions?  (i.e. terminate after 4 transitions)
    Wholesale Snapback Hats, at 9/07/'12 12:25, said:
    whether they fade in or simply appear, whether they appear in order or randomly, and more. 
    post new comment