List Grid View using jQuery
In almost every e-commerce website that you are designing, the feature
to switch between list and grid view is very essential to facilitate
better display of the huge product catalog. This is very simple to
achieve using jQuery, as you can visualize the very minimal version in
the jsfiddle showcased
here.
To make this more complete, I experimented showcasing product catalog
with fade-in and fade-out transitions while switching between grid and
list views. In this post, let us see how to create fading list/grid view
switcher with components to display product catalog using jQuery and
css.
1. First let us prepare the content to be dynamically styled according to the view selected. I have used
font-awesome
icons for displaying list and gridview switch controls in the demo and
it is absolutely optional, you can choose to use buttons or links. So
first let us place the switching controls inside body tag.
3 | < i class = "fa fa-th fa-2x" ></ i >Grid |
5 | < a class = "listview active" > |
6 | < i class = "fa fa-list fa-2x" >List</ i > |
Next let us add an unordered list containing product details. Each
list-item represents one product and I have displayed only one list
below, since it is the same for all products. In the demonstration, I
have used eight products, that means I have used the list-item eight
times.
03 | < img src = "images/barbie_8.jpg" height = "250px" width = "250px" /> |
04 | < section class = "list-left" > |
05 | < span class = "title" >PRODUCT NAME</ span > |
06 | < p >Product description goes here. Aliquam tincidunt diam varius |
07 | ultricies auctor. Vivamus faucibus risus tempus, |
10 | < div class = "icon-group-btn" > |
11 | < a title = "Add to Cart" href = "javascript:void(0);" class = "btn-cart" > |
12 | < span class = "icon-cart" ></ span > |
13 | < span class = "icon-cart-text" > |
17 | < a title = "Add to wishlist" href = "#" class = "btn-wishlist" > |
18 | < span class = "icon-wishlist" ></ span > |
19 | < span class = "icon-wishlist-text" > |
23 | < a title = "Add to Compare" href = "#" class = "btn-compare" > |
24 | < span class = "icon-compare" ></ span > |
25 | < span class = "compare-text" > |
31 | < section class = "list-right" > |
32 | < span class = "price" >$50</ span > |
33 | < span class = "detail" >< a class = "button" >Details</ a ></ span > |
2. Next we need two different css styles for displaying list and grid
views. I have not displayed miscellaneous css styles here that are not
mandatory to achieve list and grid layouts. However if you like to
design a product catalog exactly like what is shown in the demonstration
you can download this project and use it.
LIST LAYOUT
08 | border-bottom: 1px dotted #CCC; |
17 | border-bottom: 2px solid transparent; |
34 | ul.list li .list-right{ |
GRID LAYOUT
01 | ul.grid
li { float: left; width: 265px; height: 440px; border-right: 1px dotted
#CCC; border-bottom: 1px dotted #CCC;margin:20px; background:#F7F7F7; } |
02 | ul.grid li img{text-align:center;width:100%;} |
03 | ul.grid li p{display:none;} |
04 | ul.grid li .list-left{text-align:left;font-size:24px;margin-left: 10px;margin-top:10px;} |
05 | ul.grid li .icon-group-btn{font-size:14px;} |
06 | ul.grid li .list-right{display:block;width:100px;margin-left: 10px;} |
07 | ul.grid li .list-right .price{font-size:24px;display:block;color:#4FAFC2;} |
3. Finally let use jQuery to switch between grid and listviews with fade-in and fade-out effect.
01 | < script type = "text/javascript" > |
02 | $(document).ready(function () { |
04 | $('#viewcontrols a').on('click',function(e) { |
05 | if ($(this).hasClass('gridview')) { |
06 | elem.fadeOut(1000, function () { |
07 | elem.removeClass('list').addClass('grid'); |
11 | else if($(this).hasClass('listview')) { |
12 | elem.fadeOut(1000, function () { |
13 | elem.removeClass('grid').addClass('list'); |
That is all. Do not forget to include jQuery library reference inside
head tag of your html. Enjoy the demo and download the project to see
how other components inside every list-item is styled.
0 comments:
Post a Comment
Thanks for your valuable Comment