Showcases slider
Many of the sites I make use JavaScript. The last years JavaScript is being used more then Flash, because it loads faster, it is supported by more browsers (for example, by the browsers on the iPad or iPhone) and it’s more easy to maintain.
On the main page of the company-site we use JQuery to create a nice slideshow with some of our projects. The HTML of the showcases is created with PHP, the css makes sure the HTML blocks are visualized the correct way and the JavaScript finally adds the animation.
The script is activated by pressing on either the “next” or “previous” button, and JQuery UI makes sure the animation goes smooth. The script also shows a bouncing animation when there are no more showcases to show. You can try this by entering our website (link below in my bio).
Here is the script that makes the animation possible:
function homeBottomSlider(to) { var bloque = $ (‘#bloque_powered_by_home’); var step = 740;
var item = 0; if (bloque.attr(‘_current’)) { item = parseInt(bloque.attr(‘_current’),10); } if (to == ‘next’) { item++; } else { item–; } var margin_new = item * step;
if (item<0) { bloque.animate({‘margin-left’:’50px’}, {duration: 100, queue: false, complete: function() { bloque.animate({‘margin-left’:’0px’}, {duration: 500, easing: ‘easeOutBounce’, queue: false}); }}); return false; }else if (margin_new >= bloque.width()) { var bounce_start = ((item-1) * step) + 50; var bounce_end = bounce_start – 50; bloque.animate({‘margin-left’: ‘-’+ bounce_start + ‘px’}, {duration: 100, queue: false, complete: function() { bloque.animate({‘margin-left’: ‘-’+ bounce_end + ‘px’}, {duration: 500, easing: ‘easeOutBounce’, queue: false}); }}); return false; } bloque.attr({‘_current’: item}); bloque.animate({‘margin-left’: ‘-’+ margin_new + ‘px’}, {duration: 1000, easing: ‘easeInOutSine’, queue: false});}
Make sure to include the JQuery and JQuery UI scripts too. You can download these scripts at the official site of JQuery. A quick search in Google will tell you the url.
One note. When JavaScript is deactivated the site will still show the showcases, but it will not be possible to start the animation. And when there is no JavaScript and CSS available, all the showcases will be visible together as plain text (with the rest of the plain text of the site). This JavaScript solution is an accessible solution. Both for browsers for blind people and for spiders of search engines.
And, as an extra effect, we´ve attached a “fancyzoom” animation (a JQuery plugin) when a user clicks on one of the images of the showcases. This script asynchronously loads the main image and shows it in the centre of the browser.</0)>
Use and distribution of this article is subject to our Publisher Guidelines
whereby the original author’s information and copyright must be included.




