Skip to main content

Bouncy Content Filter for big Website




Bouncy Content Filter for big Website







This space-saving content filter allows the users to switch from one category to the other in a fancy way! Each click fires the rotation of the gallery images, revealing the items belonging to the selected category.












Content filters are particularly useful for big websites, where each pixel counts. Lets say you are showing the “last products” of your e-commerce. How about giving the users the option to switch to the “most popular” products without a page refresh? A good solution could be to hide the “most popular” items right behind the “last products”, then use the power of CSS3 3D Transforms to rotate the items when the user switches from one option to the other. The bounce effect is optional, but you get the idea! The rotation won’t work on older browsers like IE9, but the experience won’t be broken – just a display on/off with no transitions. Lets dive into the code!




Creating the structure




We wrapped the filter into a <nav> element. The filter structure is just an unordered list. We have 3 options, but 4 list items: the first one is a placeholder we’ll use on mobile to show the selected option (using jQuery). The placeholder will be removed (display:none) on larger screens by using media queries. Remember that we create our resources starting from mobile, so we need to think about small screens first.



<nav>
<ul>
<li class="placeholder">
<a href="#0">Option 1</a> <!-- default option on mobile -->
</li>

<li>
<a href="#0">Option 1</a>
</li>

<li>
<a href="#0">Option 2</a>
</li>

<li>
<a href="#0">Option 3</a>
</li>
</ul>
</nav>





For the gallery, we created an unordered list nested into another unordered list. The second

<ul> element is the one that will rotate, and the 3 images inside will rotate with it.



<ul>
<li>
<ul> <!-- this is the element that will rotate -->
<li>
<img src="img/thumb-1.jpg" alt="thumbnail">
</li>

<li>
<img src="img/thumb-2.jpg" alt="thumbnail">
</li>

<li>
<img src="img/thumb-3.jpg" alt="thumbnail">
</li>
</ul>
</li>

<li>
<ul> <!-- this is the element that will rotate -->
<li>
<img src="img/thumb-1.jpg" alt="thumbnail">
</li>

<li>
<img src="img/thumb-2.jpg" alt="thumbnail">
</li>

<li>
<img src="img/thumb-3.jpg" alt="thumbnail">
</li>
</ul>
</li>

<!-- ... -->
</ul>





Adding style




The first list item, therefore the image it contains, is the one visible. We give it a class .is-visible:



li.is-visible { /* the front item, visible by default */
position: relative;
z-index: 5;
}





Take in mind that the other list items – of the same unordered list – will have an absolute position: that means that the height of the unordered list will depend upon this first list item. Besides by giving it a higher z-index we make sure it sits on top.



The other 2 classes we need are .is-hidden and .is-selected – that we give to the other list items. The .is-hidden class is applied to all hidden list items, while .is-selected is applied only to the item whose category has been selected (we do this in jQuery). Note that by applying a CSS3 transformation (180deg rotation) we make sure that once the

<ul> element rotates by 180deg, we see the front of the list item that was hidden instead of its back. Oh and don’t forget to add backface-visibility: hidden; to all list items!



li.is-hidden { /* the hidden items, right behind the front one */
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
z-index: 1;
transform: rotateY(180deg);
}

li.is-selected { /* the next item that will be visible */
z-index: 3 !important;
}





Events handling




Now here is the idea: when the user clicks to change option, we use jQuery to add a .is-switched class to the

<ul> element that rotates. The purpose of this class is to allow us to change simultaneously the properties of our 3 classes:



ul.is-switched li.is-visible {
transform: rotateY(180deg);
animation: cd-rotate 0.5s;
}

ul.is-switched li.is-hidden {
transform: rotateY(0);
animation: cd-rotate-inverse 0.5s;
opacity: 0;
}

ul.is-switched li.is-selected {
opacity: 1;
}





We used CSS3 Animations to achieve the bounce effect, but CSS3 transitions would work just fine:



@keyframes cd-rotate {
0% {
transform: perspective(800px) rotateY(0);
}

70% { /* this creates the bounce effect */
transform: perspective(800px) rotateY(200deg);
}

100% {
transform: perspective(800px) rotateY(180deg);
}
}

@keyframes cd-rotate-inverse {
0% {
transform: perspective(800px) rotateY(-180deg);
}

70% {
transform: perspective(800px) rotateY(20deg);
}

100% {
transform: perspective(800px) rotateY(0);
}
}





Now some of you may be wondering: why didn’t he apply the rotation directly to the <ul> element? Because that would have made necessary to apply transform-style: preserve-3d; to the <ul> element (to allow nesting 3D transformations, because list items rotate too) . Things would have been much easier, but unfortunately preserve-3d isn’t supported by IE (up to 11). That’s why I applied the transformations to each list item instead.



Hope you enjoyed this, now go out and change the world!




Changelog

-Fixed a bug on IOS8: elements disappear during rotation

-jQuery updated to be used with more than one filter in the same page












Comments

Popular posts from this blog

Content slider with Zoom Effect for a predefined area in each slide

Zoom Slider Today’s Blueprint is a simple content slider with depth-like zoom functionality. Each slide has a predefined zoom area that will be used to calculate the appropriate scale value for a fullscreen fill. Once the icon for zooming is clicked, the zoom area as well as the page get scaled, creating the illusion that the viewer is approaching the item. Once the whole page is covered, we show some more details. Navigating the slider will animate the inner parts of the slide, allowing for an independent control of the image area and the title. We are using CSS transitions and dymanic.js for moving the slide elements. Dymanic.js by MichaĆ«l Villar is a JavaScript library to create physics-based animations. Please note that we are using a couple of modern CSS properties, so only contemporary browsers are supported. The HTML <!-- Main container --> <div class="container"> <!-- Blueprint header --> <header class="bp-header cf"> ...

An AJAX Based Shopping Cart with Drap Drop Item Effect

An AJAX Based Shopping Cart In this tutorial we will create an AJAX Based Shopping Cart with Drag and Drop feature.You can easily use this shopping cart in you store.All the products are going to be stored in a MySQL database, with PHP showing and processing the data. So go ahead, download the demo files and start reading. Step 1 – the MySQL Database If you want to set up a working demo, you’ll need to execute the following SQL code in your database manager (e.g. phpMyAdmin). It will set up the table and insert a few products. The code is also available in table.sql in the demo files. table.sql CREATE TABLE IF NOT EXISTS `internet_shop` ( `id` int ( 6 ) NOT NULL auto_increment, `img` varchar ( 32 ) collate utf8_unicode_ci NOT NULL default '' , `name` varchar ( 64 ) collate utf8_unicode_ci NOT NULL default '' , `description` text collate utf8_unicode_ci NOT NULL , `price` double NOT NULL default '0' , PRIMARY K...