Easy Display Switch with CSS and jQuery

By Soh Tanaka | Published March 9th, 2009 in Tutorials

Today, I would like to go over a quick and simple way to allow your users to switch page layouts by using CSS and jQuery.

Today’s web users expect web pages to be increasingly more interactive. To this end, the ability to change page layouts provides your users with a more immersive experience and allows them to consume information more easily, either with a quick gallery view, or a detailed summary view.

Display Switch Tutorial:

View Demo of Display Switch

Display Switch Sample

Step1. Creating the Wireframe

We will first start out designing the vertical list layout with a simple unordered list which we will use as our columns/rows.

HTML

<ul class="display">
    <li></li>
    <li></li>
    <li></li>
</ul>

CSS
*Note I used different shades of grey to achieve the subtle bevel look.

ul.display li a {
    color: #e7ff61;
    text-decoration: none;
}
ul.display li .content_block {
    padding: 0 10px;
}
ul.display li .content_block h2 {
    margin: 0;
    padding: 5px;
    font-weight: normal;
    font-size: 1.7em;
}
ul.display li .content_block p {
    margin: 0;
    padding: 5px 5px 5px 245px;  /*--The left padding keeps the
content from flowing under the image--*/

    font-size: 1.2em;
}
ul.display li .content_block a img{ /*--Double border technique--*/
    padding: 5px;
    border: 2px solid #ccc;
    background: #fff;
    margin: 0 15px 0 0;
    float: left;
}

Step2. Styling the Content

Inside of each list item, we nest a div which will act as our container of the content inside. I feel it’s easier to calculate the columns when you don’t have to consider the margin and padding within. This comes in handy especially when you are working with a liquid layout (since we know % and fixed pixels don’t mix in too well).

HTML

<li>
        <div class="content_block">
            <a href="#"><img src="sample.gif" alt="" /></a>
            <h2><a href="#">Image Name</a></h2>
            <p>Description goes here</p>
        </div>
    </li>

CSS

ul.display li a {
    color: #e7ff61;
    text-decoration: none;
}
ul.display li .content_block {
    padding: 0 10px;
}
ul.display li .content_block h2 {
    margin: 0;
    padding: 5px;
    font-weight: normal;
    font-size: 1.7em;
}
ul.display li .content_block p {
    margin: 0;
    padding: 5px 5px 5px 245px;  <span style="color: #777;">/*--The left padding keeps the
content from flowing under the image--*/
</span>
    font-size: 1.2em;
}
ul.display li .content_block a img{ <span style="color: #777;">/*--Double border technique--*/</span>
    padding: 5px;
    border: 2px solid #ccc;
    background: #fff;
    margin: 0 15px 0 0;
    float: left;
}

Step3. Creating the Secondary View Option

Now its time to style the second display option which are in columns flowing horizontally.

Adding jQuery

CSS

ul.thumb_view li{ width: 250px; } <span style="color: #777;">/*--Switch the width
to accommodate for the three column layout--*/
</span>
ul.thumb_view li h2 { display: inline; }
ul.thumb_view li p{ display: none; }
ul.thumb_view li .content_block a img { margin: 0 0 10px; }

Step4. Creating the Switch

Time to wrap up this tutorial by creating the switch.

Switch Button

HTML

<a href="#" class="switch_thumb">Switch Display</a>

CSS
Using the ‘CSS Sprites’ technique, I create the link button.

a.switch_thumb {
    width: 122px;
    height: 26px;
    line-height: 26px;
    padding: 0;
    margin: 10px 0;
    display: block;
    background: url(switch.gif) no-repeat;
    outline: none;
    text-indent: -9999px;
}
a.swap { background-position: left bottom; }

I didn’t feel like creating a hover state on the image, so I’ll just use the opacity to dim it down a tad bit once hovered over.

a:hover.switch_thumb {
    filter:alpha(opacity=75);
    opacity:.75;
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=75)";
}

jQuery
At last, we’ll activate the switch with a little bit of jQuery.

<script type="text/javascript">
$(document).ready(function(){

    $("a.switch_thumb").toggle(function(){
        $(this).addClass("swap");
        $("ul.display").fadeOut("fast", function() {
            $(this).fadeIn("fast").addClass("thumb_view");
        });
    }, function () {
        $(this).removeClass("swap");
        $("ul.display").fadeOut("fast", function() {
            $(this).fadeIn("fast").removeClass("thumb_view");
        });
    });

});
</script>

Final View

View Demo of Display Switch

Display Switch Sample

Now Go and Experiment!

This method can be applied to many scenarios, so I would like to encourage you to experiment with this technique. If you have any other tricks to add on, please feel free to drop your comments!

About the Author:

Soh Tanaka is a Web Designer and blogger from Los Angeles. For more front-end web development tutorials, check out his blog or you can follow him on twitter @SohTanaka


228 Comments
  1. Jesse Foster on March 9th, 2009

    Very nice. Simple technique with excellent results.

    Good job.

  2. Will on March 9th, 2009

    Very impressive; I’m not exactly sure how I will implement this yet, but I’ll let you know!

  3. Jad Limcaco on March 9th, 2009

    This is an awesome tutorial. Thank you and I will definitely be using this.

  4. Tracey Grady on March 9th, 2009

    Nice effect, Soh. I just wonder how it looks to a site visitor who has javascript turned off?

    Where possible I think it’s important to use javascript functions which degrade gracefully, and if this does so then that would be doubly useful.

  5. [...] Easy Display Switch with CSS and jQuery [...]

  6. Tom on March 9th, 2009

    MMMMMMMMMMMM

    Nice!!

  7. Jean-Baptiste Jung on March 9th, 2009

    Excellent tutorial! I definitely should implement it on one of my blogs!

  8. DamirK on March 9th, 2009

    Nice…

  9. joyoge designers' bookmark on March 9th, 2009

    nice work, thanks for the helpful tut..

  10. Bruno on March 9th, 2009

    Great tut!
    It´ll help a lot my recent project!

  11. Jacob Gube on March 9th, 2009

    Great tutorial Soh!

  12. popurls.com // popular today…

    story has entered the popular today section on popurls.com…

  13. Sérgio Soares on March 9th, 2009

    awesome work :)

  14. theBagg on March 10th, 2009

    Just a little bug if you double click the switch view button. The views get mixed up.

  15. cougar on March 10th, 2009

    That’s cooooool.

  16. [...] Easy Display Switch with CSS and jQuery [...]

  17. Mike Mella on March 10th, 2009

    Tracey Grady’s right. Graceful degradation is important, and this does not accommodate that.

    Looks cool otherwise though.

  18. sky on March 10th, 2009

    wow..it’s so cool bro..

    thank u for your post..

  19. Wireframing Tools on March 10th, 2009

    i got the same thing as theBagg.

  20. Branden Silva on March 10th, 2009

    How hard would it be to add pagination into this? I love the effect and would love to have 3 different display types, along with pagination to reduce the load times of a million images.

  21. izzat aziz on March 10th, 2009

    never thought it actually that simple.
    i think it gonna use some crazy java
    code, but nope. it just that..

    thanks.

  22. Neon on March 10th, 2009

    Fantastic! Such a simple idea and simple code too for a fabulous result.

  23. noelmcg on March 10th, 2009

    great tutorial cheers

  24. [...] Easy Display Switch with CSS and jQuery (tags: css jquery javascript) [...]

  25. Vini on March 10th, 2009

    This is a simple but awesome thing! Congratulations!

  26. Bill Lowden on March 10th, 2009

    Very nice, and the code is well documented and easy to follow. Thanks.

  27. François on March 10th, 2009

    Thanks a lot! Wonderful piece of code!
    It will be useful for my future projects!!!

  28. Soh Tanaka on March 10th, 2009

    Thank you all for the comments, Im glad that you guys liked it. Looking forward to seeing some nice stuff with this technique :-)

    @Tracey Grady, @Mike Mella, when javascript is turned off, there is nothing hindering the user from the content since all we are doing is showing them less info when the button is clicked. To make the button not appear when js is turned off, we can simply add a “display: none;” on the button, and .show() once jquery is done loading :-)

    @theBagg, @WireframingTools, can you please let me know which browser had the buggy issue? I was trying to make it skip but I wasn’t able to pull it off.

    Thank you again!~

  29. evertt de sousa on March 10th, 2009

    Incredible :) Very nice

    thank you

  30. Timothy on March 10th, 2009

    Pretty slick

  31. [...] Easy Display Switch with CSS and jQuery [...]

  32. Craig on March 10th, 2009

    It’s great to see how easy such an elegant effect can be coded. Thanks gor the tutorial.

  33. Chris Casarez on March 10th, 2009

    Well written and easy enough for a CSS layman to follow!

  34. [...] Easy Display Switch with CSS and jQuery A really nice way to dynamically load alternating CSS files to switch styles! (tags: css jquery javascript webdesign ajax) [...]

  35. [...] Easy Display Switch with CSS and jQuery (tags: jquery webdesign css javascript styleswitcher) « links for 2009-03-09 [...]

  36. [...] Easy Display Switch with CSS and jQuery Great tutorial of jQuery and CSS Display Switch (tags: webdev tutorials jquery javascript tutorial css ajax) [...]

  37. Nokadota on March 11th, 2009

    This would be great for a gallery, thanks for the tut Sol.

  38. Brian Wilcox on March 11th, 2009

    I was looking for a nice way to promote some category thumbnails with different variations.

    I just found it! Nice work Tanaka.

  39. [...] Easy Display Switch with CSS and jQuery A very slick result (tags: css jquery switch) [...]

  40. Jens on March 11th, 2009

    Who have javascript turned off these days :) ?

    I whould sure use it!

  41. [...] a quick and simple way to allow your users to switch page layouts by using CSS and jQuery on “Easy Display Switch with CSS and jQuery“. The technique is quite simple but the result is very nice and [...]

  42. stack on March 11th, 2009

    nice but you miss one point
    another switch to the real size of the image would be great
    as i got my own portfolio with thumbnail, normal size and big size

    and no i dont want another lightbox for big size
    only jquery rocks !!

    ;)

  43. Mendoza Opina on March 11th, 2009

    nice!!! :)

  44. Jean on March 11th, 2009

    No cookie to remember witch layout was last used?
    Quite useless…

  45. [...] Switch Page Layouts – easily switch page layouts by using CSS and jQuery. [...]

  46. George on March 11th, 2009

    Soh,
    Good stuff – helpful to many!

  47. Komang on March 11th, 2009

    Great! simple but excellent result

  48. David D on March 12th, 2009

    Very nice.
    I’m going to have to learn me some jquery.

    Layout works fine with javascript disabled, but none of the switching works. That doesn’t seem to be a problem for anyplace that I would use this.

  49. Frank on March 12th, 2009

    Very nice!

    Would be good to add a cookie to remember the last layout.

    How would you invert the process from thumb view to list?

    thanks!

  50. [...] Easy Display Switch with CSS and jQuery (tags: jquery webdesign css styleswitcher) [...]

  51. Martin Sarsini on March 12th, 2009

    Simply beautiful!

  52. xene on March 12th, 2009

    useful tutorial. Thanks a lot

  53. [...] Easy Display Switch with CSS and jQuery Easy Display Switch with CSS and jQuery on Design M. [...]

  54. Soh Tanaka on March 12th, 2009

    Hey guys, I’m looking into the cookie issue, I had this in mind when making this tutorial so it was actually intended for a smaller site w/out paging. But to make this useful for sites of all sizes, its a must~

    @Frank, If you want to reverse the order, your going to have to set the default list style to have the thumbs first, and in your jquery, your going to addClass your list style to the thumb layout. Also don’t forget to change the css sprites on the button as well~

  55. Steph on March 12th, 2009

    OMG, I want to use this! It’s so snazzy! Thanks.

  56. [...] Easy Display Switch with CSS and jQuery – Offer multiple views of your web content! [...]

  57. Igor on March 13th, 2009

    Very nice and simple! thank you!

  58. [...] via Easy Display Switch with CSS and jQuery. [...]

  59. xavo on March 14th, 2009

    mmm.. good idea!!

  60. Joefrey on March 16th, 2009

    Great Tutorial! I’m gonna surely use this this technique! Thanks for sharing!

  61. Joefrey on March 16th, 2009

    Can you try to use cookie on this? Like on the bestwebgallery style. Because everytime I open the demo it will back to the default style.

  62. [...] Easy Display Switch with CSS and jQuery Today, I would like to go over a quick and simple way to allow your users to switch page layouts by using CSS and jQuery. [...]

  63. [...] more easily, either with a quick gallery view, or a detailed summary view. With this awesome jQuery tutorial, you can allow your users to switch page layouts in a very easy manner. Also it looks so [...]

  64. SB on March 16th, 2009

    nice

  65. David D on March 16th, 2009

    Well, it’s a 94% solution for me.

    It works great in Firefox and Explorer. But it looks like the switching part is broken in Chrome and Safari. The content_block DIVs have the correct width, but they end up being a narrow list on the left side of the page.

    I’ll still use it on a personal site, but even with only 6% Safari users, I can’t use this on one of my ecommerce sites.

  66. solona on March 17th, 2009

    Nice!

  67. Owl on March 17th, 2009

    Will work perfectly on my webshop =)

  68. [...] Nah ini yang ditunggu-tunggu, image gallery dapat berubah (switch) dengan simple konsep dari thumbnail kecil hingga ada spesifik dengan keterangan seperti contoh gambar diatas. Jika ingin mengetahui cara-cara membuat switch view gallery, kunjungi disini. [...]

  69. [...] Continue reading here. Share and Enjoy: [...]

  70. [...] Easy Display Switch with CSS and jQuery a quick and simple way to allow your users to switch page layouts by using CSS and jQuery. (tags: webdesign webdev jquery css tutorial gallery style styleswitcher) No TweetBacks yet. (Be the first to Tweet this post) Sure, go on and share this [...]

  71. [...] Easy Display Switch with CSS and jQuery [...]

  72. Jhon Doe on March 23rd, 2009

    good job!!

  73. [...] us a quick and simple way to allow your users to switch page layouts by using CSS and jQuery on “Easy Display Switch with CSS and jQuery“. The technique is quite simple but the result is very nice and [...]

  74. [...] Easy Display Switch with CSS & jQuery [...]

  75. [...] How To » Easy Display Switch with CSS and jQuery [...]

  76. fonso gfx on March 30th, 2009

    Great tutorial.:)

  77. Allie on March 30th, 2009

    Awesome tutorial, I’ve been looking for something like this :D

  78. Franky on March 30th, 2009

    Hi there,

    First off all, very nice trick with css and jquery.
    I do have a question though. Would it be possible (easy) to add a “third” display option?

    I am very new to jquery and wouldnt exactly know if toggle could accomplish what i am looking for.

    Hope to hear from you.

    Thanks!

  79. samir on March 30th, 2009

    Great idea, thanks for the tip.

  80. [...] Easy Display Switch with CSS and jQuery | change, css, display, jquery, layout, swap, switch, view [...]

  81. modja on April 6th, 2009

    this very cool, thx for share

  82. wallan on April 13th, 2009

    Man you know how to make a good tutorial. Great

  83. sonvm on April 17th, 2009

    Thanks for share ! I like this :-)

  84. erw13n on April 19th, 2009

    Wow, never though that Tabs can use like this.
    Nice idea

  85. Barbaros Alp on April 20th, 2009

    Good idea, great.

  86. ArranM on April 30th, 2009

    Very nice, i would think about adding a cookie, so it remembers your switch view for the next time you visit.

    thanks for sharing.

  87. בניית אתרים on April 30th, 2009

    Very nice mate keep Up…
    its possible to start with the thumb_view (2)
    10X mate

  88. [...] 3. Easy Display Switch with CSS and jQuery [...]

  89. [...] Easy Display Switch with CSS and jQuery(Via: DesignM.ag), Demo Category: Tutorial| Tags: jQuery, Switch |Permalink [...]

  90. Setiaji on May 8th, 2009

    Thank you so much, this tutorial give me some idea..!!

    Thank you..

  91. [...] Easy Display Switch with CSS and jQuery | change, css, display, jquery, layout, swap, switch, view [...]

  92. [...] Switch Page Layouts – easily switch page layouts by using CSS and jQuery. [...]

  93. GreyK50 on June 22nd, 2009

    Awesome Tuts Soh, thanks for sharing this.

  94. [...] Easy Display Switch with CSS and jQuery This tutorial outlines a method for using jQuery to smoothly-transition into different viewing modes, which can be helpful in image galleries. [...]

  95. [...] Easy Display Switch with CSS and jQuery This tutorial outlines a method for using jQuery to smoothly-transition into different viewing modes, which can be helpful in image galleries. [...]

  96. [...] Easy Display Switch with CSS and jQuery This tutorial outlines a method for using jQuery to smoothly-transition into different viewing modes, which can be helpful in image galleries. [...]

  97. [...] Easy Display Switch with CSS and jQuery [...]

  98. [...] Easy Display Switch with CSS and jQuery This tutorial outlines a method for using jQuery to smoothly-transition into different viewing modes, which can be helpful in image galleries. [...]

  99. [...] Tutorial auf designm.ag zeigt wie man ganz einfach mit CSS und jQuery ein Gallery-Ansicht zu einer detailierten [...]

  100. [...] Easy Display Switch with CSS and jQuery (tags: jquery ui css) [...]

  101. lee on June 25th, 2009

    Great script; can think of many uses.

    But: is there a way to stop it from jumping to the top of the page when one clicks the switch?

  102. Nick on June 25th, 2009

    Soh, Were you ever going to get it working with a cookie? That would be really appreciated.

  103. Alcor on July 6th, 2009

    Awesome script. Thanks for sharing.

  104. [...] Easy Display Switch with CSS and jQuery This tutorial outlines a method for using jQuery to smoothly-transition into different viewing modes, which can be helpful in image galleries. [...]

  105. Josh on July 22nd, 2009

    Pretty freakin’ sweet! I put this tutorial to good use at 83themes.com. Thanks for making it so easy!

  106. Dax Hansen on July 31st, 2009

    Thank you so much, that’s an awesome gallery! So fresh and so clean, clean.

  107. WAMPvn on August 1st, 2009

    been searching all over Google for a non-complicated way to add reviews and ratings and it looks like this is it.

    Thank you a million times over.

  108. [...] http://designm.ag/ Format: CSS, jQuery Tutorial Link: Tutorial Bilderanzeige mit css und jquery switchen Thread [...]

  109. Rihanna Lee on August 12th, 2009

    Did any one ever figure out how to keep the page from jumping back to the top of the site? – Rihanna

  110. martin.cui on August 12th, 2009

    Very Nice,It is a good job!!!

  111. SP on August 12th, 2009

    Very very cool!

    I have been trying and trying to get the cookie to work because I have multiple pages but just can’t get it. Did ANYONE get a working version with a saved cookie?

  112. Website Design Services on August 13th, 2009

    That is a great display switch plugin! I might have to use this with a project I am working on (:

  113. Annette on August 13th, 2009

    I’m also running into a page jump problem. I tried to replace the “#” hashes with a…

    onclick=”return false;”

    … but that doesn’t fix the issue. Any idea?

    A URL example is available by clicking my name link.

  114. Flow on August 19th, 2009

    Can someone tell me how i can use that gallery seperately twice or more often on one site?
    So that i can have different categories and when i change the display method of one category only this one changes and not all on the site.

  115. [...] Easy Display Switch with CSS and jQuery This tutorial outlines a method for using jQuery to smoothly-transition into different viewing modes, which can be helpful in image galleries. [...]

  116. DevNet on September 3rd, 2009

    Nice. The good thing is that its simple and easy to read for anyone!

  117. [...] Easy Display Switch with CSS and jQuery A tutorial by Soh Tanaka on DesignM.ag that shows how you can achieve a similar effect as Best Web Gallery to give visitors layout options. [...]

  118. Egypt Web design company on September 9th, 2009

    Very Nice,It is a good job!!!
    thanks so much

  119. Andrew on October 19th, 2009

    Great tutorial. Thanks for taking the time to write this!

  120. Ronald Nunez on October 21st, 2009

    I’ll use this on one of my projects. this is very helpful, thanks for sharing your knowledge

  121. Steve on October 24th, 2009

    Cool, this is excellent. I will definately be using it on my site…..

  122. [...] #8 – Easy Display Switch with CSS and jQuery [...]

  123. designfollow on October 29th, 2009

    thanks for this great tutorial.

  124. sivakumar on October 31st, 2009

    we can use this for wallpaper websites… or photo sharing websites…But we should store this in database

  125. [...] Vertically Scrolling Menu Easy Display Switch with CSS and jQuery [...]

  126. Alexander on November 13th, 2009

    nice one, even tho a cookie is missing ;)

  127. Marc on November 17th, 2009

    Hi this is very nice. I have everything working except the image for the switch doesn’t show. The spot is a hot spot and toggles but for some reason I can’t get the switch.gif to show up any suggestions?
    thanks

  128. [...] Some people prefers to read a list of blog exerpts in lines, so other prefers a column display. With this tutorial you’ll learn how to create a jQuery display switch so your readers will be able to choose their favorite display. » Ver Tutorial [...]

  129. Nox on November 20th, 2009

    Hello,
    great tut!
    Can someone tell me how i can show the thumb gallery first?
    thx

  130. Evan Smith on November 24th, 2009

    When you’re thinking about graceful degradation, you have to think, “Is this functional and usable to everyone?” So with consideration to javascript and the Switching Views, I’d say this degrades gracefully… it’s layout is still semantic XHTML with CSS. There’s only one catch. If javascript is not available to the user viewing this, they still see the list of items/images, they just don’t have the added feature available to switch views. So a tweak to this solution would be to write the switch_view div using javascript, so that if js isn’t available, then the user won’t even see the option to switch views. Otherwise… if you absolutely must have this necessary feature that degrades gracefully and all that marketing hype you scanned over on alistapart, you would have to work it in using some server side language to control the styles (which would require a page reload at least once until the option is set).

  131. Mark on November 28th, 2009

    If you want to prevent it from causing the page to jump to the top, remove the hyperlink and use span instead.

  132. [...] us a quick and simple way to allow your users to switch page layouts by using CSS and jQuery on “Easy Display Switch with CSS and jQuery“. The technique is quite simple but the result is very nice and [...]

  133. Master cleanse weight loss on December 22nd, 2009

    Nice One. Very Appreciative.

    It helped me save a lot of time and effort with the readymade coding posted here.

  134. Sam on December 27th, 2009

    You can simplify this script using the ‘toggleClass’ function in jQuery:

    $(“span.switch_thumb”).click(function () {
    $(“span.switch_thumb”).toggleClass(“swap”);
    $(“ul.display”).fadeOut(“fast”, function() {
    $(this).fadeIn(“fast”).toggleClass(“thumb_view”);
    });
    });

    Also, if you want to use a cookie to remember the view state, use the jQuery cookie plugin (http://www.stilbuero.de/index.php?PHPSESSID=09n8bbbakpkaamhk6hirk168f6&s=cookie&x=0&y=0), and then add to your code like this:

    $(“span.switch_thumb”).click(function () {
    $(“span.switch_thumb”).toggleClass(“swap”);
    $(“ul.display”).fadeOut(“fast”, function() {
    $(this).fadeIn(“fast”).toggleClass(“thumb_view”);
    });
    $.cookie(‘view_State’, $(‘ul.display’).is(‘.thumb_view’) ? ‘list’ : ‘thumbs’ );
    });
    // COOKIES
    // view state
    var view_State = $.cookie(‘view_State’);
    // Set the user’s selection for the viewState
    if (view_State == ‘thumbs’) {
    $(“ul.display”).addClass(“thumb_view”);
    $(“span.switch_thumb”).addClass(“swap”);
    };

  135. [...] grid view or as a detailed list view. All this was done with some jQuery magic. NetTuts+ and DesignMag have some great tutorials on how to do it [...]

  136. Jared on January 2nd, 2010

    Any restrictions on usage? Can I put this into my templates that I distribute and or sell? I build WordPress themes.

  137. Steven Snell on January 2nd, 2010

    Jared,
    Feel free to use it in your templates or themes.

  138. [...] information more easily, either with a quick gallery view, or a detailed summary view.” Demo | Project [...]

  139. [...] Hay gente que prefiere ver una lista de imágenes con título en vez de mostrar más texto. así de un simple vistazo se puede mostrar mucho más contenido, puedes ver un tutorial para tratar imágenes con Css y JQuery y dar a tus usuarios la opción de cambiar la vista al vuelo. Ver tutorial >> [...]

  140. [...] How to Create an Image Gallery with easily Switchable Views [...]

  141. [...] How to Create an Image Gallery with easily Switchable Views [...]

  142. Justin on January 22nd, 2010

    This is a great tutorial, I’m a big fan of your work mr. Tanaka, thank you for putting time back into the community. You can see my working version of this scrip on my blog: domeprojects.com Thanks again.

  143. [...] ease of design, and he is kind enough to give back to the community in a major way. His tutorial Easy Display Switch with CSS and JQuery made setting up this feature a [...]

  144. [...] Homepage:http://designm.ag/tutorials/jquery-display-switch/ [...]

  145. Alex on February 14th, 2010

    Thanks for share. I was looking for it.
    Its simple and easy to read for anyone, great!

  146. Mohamed kaja on February 15th, 2010

    Awesome work friend….

  147. [...] how to manually change a layout, and it shows two great examples and “how they did it.”Easy Display Switch with CSS and jQueryA quick and simple way to enable users to switch page layouts using CSS and jQuery.Quick Tip – [...]

  148. d:e:m on February 18th, 2010

    I use it in my website http://www.danilab.net , very nice, Soh Tanaka!!

  149. [...] Easy Display Switch with CSS and jQueryA quick and simple way to enable users to switch page layouts using CSS and jQuery. [...]

  150. Bruce on February 18th, 2010

    Thanks for sharing! Nice and easy… Will be using it on a new project!

  151. [...] Easy Display Switch with CSS and jQueryA quick and simple way to enable users to switch page layouts using CSS and jQuery. [...]

  152. [...] Easy Display Switch with CSS and jQuery A quick and simple way to enable users to switch page layouts using CSS and jQuery. [...]

  153. Dieter on February 18th, 2010

    I also wanted to use this with cookies and I tired the Sam’s suggestion with no luck:

    “You can simplify this script using the ‘toggleClass’ function in jQuery:

    $(“span.switch_thumb”).click(function () {
    $(“span.switch_thumb”).toggleClass(“swap”);
    $(“ul.display”).fadeOut(“fast”, function() {
    $(this).fadeIn(“fast”).toggleClass(“thumb_view”);
    });
    });

    Also, if you want to use a cookie to remember the view state, use the jQuery cookie plugin (http://www.stilbuero.de/index.php?PHPSESSID=09n8bbbakpkaamhk6hirk168f6&s=cookie&x=0&y=0), and then add to your code like this:

    $(“span.switch_thumb”).click(function () {
    $(“span.switch_thumb”).toggleClass(“swap”);
    $(“ul.display”).fadeOut(“fast”, function() {
    $(this).fadeIn(“fast”).toggleClass(“thumb_view”);
    });
    $.cookie(‘view_State’, $(‘ul.display’).is(‘.thumb_view’) ? ‘list’ : ‘thumbs’ );
    });
    // COOKIES
    // view state
    var view_State = $.cookie(‘view_State’);
    // Set the user’s selection for the viewState
    if (view_State == ‘thumbs’) {
    $(“ul.display”).addClass(“thumb_view”);
    $(“span.switch_thumb”).addClass(“swap”);
    };

    It won’t change views anymore if I use this. Any suggestions?

  154. Ivan on February 19th, 2010

    Cool effect! Thanks man!

  155. [...] Easy Display Switch with CSS and jQuery A quick and simple way to enable users to switch page layouts using CSS and jQuery. [...]

  156. [...] Easy Display Switch with CSS and jQuery A quick and simple way to enable users to switch page layouts using CSS and jQuery. [...]

  157. [...] Easy Display Switch with CSS and jQueryA quick and simple way to enable users to switch page layouts using CSS and jQuery. [...]

  158. wptidbits on February 19th, 2010

    Wow! I’ve been looking for this feature. Now my other site just using different theme to change the display type. But this, is like amazing! Might compatible with wordpress? I’ll try this..

  159. [...] Easy Display Switch with CSS and jQueryA quick and simple way to enable users to switch page layouts using CSS and jQuery. [...]

  160. Web Guru on February 22nd, 2010

    This is a nice fine for me. Cool effect.

  161. [...] Easy Display Switch with CSS and jQuery A quick and simple way to enable users to switch page layouts using CSS and jQuery. [...]

  162. hugo on February 22nd, 2010

    +1 for a cookie ! thanks

  163. [...] Homepage:http://designm.ag/tutorials/jquery-display-switch/ [...]

  164. Rajesh Trilokhria on February 24th, 2010

    I defiantly liked the tutorial and this made me to think why would a user would like to see such features and functionality if at the very next refresh of the page his/her preference will get flushed….

    How do other people think about this and how can we take this really awesome tutorial to the next level.

  165. Evan Smith on February 25th, 2010

    Some people were asking about the ‘jump’ that happend on the anchor (a href=”") element. This will always happen on an anchor/href element. Change the switch trigger to something else. I think just deleting the href=”" altogether will work. A better solution would be to change it to a (button) element.

  166. Yen Howell on February 25th, 2010

    It doesn’t work :S

  167. Retro Sweets Hamper on February 26th, 2010

    Great tutorial, the switch is so useful… just need to find a use now!

  168. [...] Easy Display Switch with CSS and jQuery – DesignM.ag Today’s web users expect web pages to be increasingly more interactive. To this end, the ability to change page layouts provides your users with a more immersive experience and allows them to consume information more easily, either with a quick gallery view, or a detailed summary view. (tags: tutorial css webdesign styleswitcher switch) [...]

  169. [...] explains how to manually change a layout, and it shows two great examples and “how they did it.”Easy Display Switch with CSS and jQueryA quick and simple way to enable users to switch page layouts using CSS and jQuery.Quick Tip – [...]

  170. FB on March 4th, 2010

    Great tut Soh,

    for those of you that cannot get the cookie to set,
    from the kind offer of the code by ‘Sam’ you need to replace the curly quotes that the comment system has added and replace them with normal double quotes, if that makes sense…

  171. AA on March 5th, 2010

    Hi
    I tried that one out but i doesnt work. The css is incomplete.

  172. [...] Easy Display Switch with CSS and jQuery Go To Source [...]

  173. [...] Tutorial Tutorial Page [...]

  174. padexx on March 11th, 2010

    For all still having problems with the cookies enabled version. Here is the complete working script code:
    http://padexx.pa.ohost.de/togglecookies.txt

    And you also need the above mentioned jquery cookies plugin and call it right after your jquery call.
    http://plugins.jquery.com/project/cookie

  175. AAA on March 21st, 2010

    Is there a way to change the layout from three to four, or more in a row. I attempted to change the size of the containers to have it auto adjust, however that has not worked. Any Suggestions?

  176. tomasz on March 24th, 2010

    Great tutorial but I have question how I can change default view. I would like that on loaded page will be quick gallery view as default view. What I should change?

  177. mack on March 31st, 2010

    this design is useful. cool effect. Especial when i need to display a lot images in only one page with many words.

  178. Steven on April 1st, 2010

    So cool. I will try it.

  179. Drid on April 19th, 2010

    Nice!!

    Any idea how to make the toggle persistent (w/ cookies)?

  180. Rohan on April 22nd, 2010

    Sweet dude. That looks amazing!

  181. crusher on May 5th, 2010

    It’s useful, i like it . it can be used for my wesite.
    jquery is so cool.

  182. agnes on May 13th, 2010

    Hi! Thanks for the tutorial.. wow.. i did it on the design that i am working with :) thanks again!!!

  183. Ricardo Zea on May 20th, 2010

    Page jumps.

    Using didn’t work to avoid the page jumping back up if the switch view action is down the page.

    Using “event.stopPropagation();” in the function, didn’t work either.

    Using fadeTo() instead of fadeOut() and fadeIn() didn’t work either.

    Any other ideas on how to stop the page from jumping?

  184. Ricardo Zea on May 20th, 2010

    Some basic code got stripped out of my post.

    I mean to say that using >spans< (had to invert the brackets) didn't work.

  185. CMentality on May 21st, 2010

    Hello,

    There are some sort of unsupported lines in the jQuery/cookie code.
    After 2 errors in the Markup Validation, it can’t even check my pages anymore.
    Is there somebody who can help me with this? It’s the following code that has some lines which cannot interpret as utf-8 (in other words, the bytes found are not valid values in the specified Character Encoding).

    $(“a.switch_thumb”).click(function () {
    $(“a.switch_thumb”).toggleClass(“swap”);
    $(“ul.display”).fadeOut(“fast”, function() {
    $(this).fadeIn(“fast”).toggleClass(“thumb_view”);
    });

    $.cookie(‘view_State’, $(‘ul.display’).is(‘.thumb_view’) ? ‘list’ : ‘thumbs’ );
    });

    // COOKIES
    // view state
    var view_State = $.cookie(‘view_State’);
    // Set the user’s selection for the viewState
    if (view_State == ‘thumbs’) {
    $(“ul.display”).addClass(“thumb_view”);
    $(“span.switch_thumb”).addClass(“swap”);
    };

    });

    I think I got the error in the line that is bold.

  186. CMentality on May 21st, 2010

    Got the problem and can validate again.
    The problem was in this line:

    // Set the users selection for the viewState

  187. dattai on June 19th, 2010

    Useful article

    Thanks

  188. Dayanand on June 23rd, 2010

    Hi,

    Stepwise decleration of CSS is good it is easy to learn. We can design the template using this tips.

    Deep from Website Development Company : http://www.e-profitbooster.com

    Our Services :

    • Website Designing
    • Web Development
    • PHP Development
    • ASP.NET Development
    • E-Commerce Website
    • Website Re-designing and Maintenance
    • Banner Designing
    • E-Learning
    • Domain Services and Maintenance

  189. grinding mill on July 3rd, 2010

    very good, very strong ………..

  190. raymond mill on July 3rd, 2010

    Thank you for your share and your useful information.

  191. cone crusher on July 6th, 2010

    Hi! Thanks for the tutorial.. wow.. i did it on the design that i am working with :) thanks again!!!

  192. discount louis vuitton on July 10th, 2010

    it’s really useful thanks a lot

  193. Jennifer R on July 10th, 2010

    It’s amazing tutorial, I now apply it to my theme , thank you

  194. Website design chennai on July 12th, 2010

    Very useful tutorial for designers…very simple and its veryworthfull..good

  195. bailey on July 18th, 2010

    It’s useful, i like it . it can be used for my wesite.
    jquery is so cool.

  196. Criss on July 18th, 2010

    it is not clear how to have the “thumb view” instead of “list view” when the page loads. Could you be more specific?

  197. louis on July 23rd, 2010

    It’s useful, i like it . it can be used for my wesite.
    jquery is so cool.

  198. vuitton hanbags on July 23rd, 2010

    It’s useful, i like it . it can be used for my wesite.
    jquery is so cool.

  199. seminyak hotels on July 23rd, 2010

    great tutorial thanks

  200. LV on July 24th, 2010

    love it

  201. Adam Cooper on July 24th, 2010

    I tried this on a recent project and it works well.

  202. Menekis on July 26th, 2010

    For the invert function I have a little problem, everything seems to go well except that I need to press twice on the swap button for the first change.

    $(document).ready(function(){

    $(“a.switch_thumb”).toggle(function(){
    $(this).addClass(“swap”);
    $(“ul.display”).fadeOut(“fast”, function() {
    $(this).fadeIn(“fast”).addClass(“thumb_view”);
    });
    }, function () {
    $(this).removeClass(“swap”);
    $(“ul.display”).fadeOut(“fast”, function() {
    $(this).fadeIn(“fast”).removeClass(“thumb_view”);
    });
    });

    });

    I guess my problem is in the script but I don’t understand what I need to change in it.

    thx for your help

  203. grindind mill on July 27th, 2010

    nice but you miss one point
    another switch to the real size of the image would be great
    as i got my own portfolio with thumbnail, normal size and big size

    and no i dont want another lightbox for big size
    only jquery rocks !!

  204. stone crusher machine on July 28th, 2010

    I am really not sure, I’m looking for a long time effect, this effect was so beautiful, thank you for sharing, I think you are greater than Obama.

  205. fanggaofeng on August 2nd, 2010

    Thank you for your share!
    Just a little bug if you double click the switch view button. The views get mixed up.

  206. Ramakant Yadav on August 4th, 2010

    It’s great tutorial and your technique is so cool.
    Well done go ahead.

    Thanks
    Ramakant Y.

  207. stone crusher on August 4th, 2010

    Thank you for your share!
    It’s useful, i like it . it can be used for my wesite.
    jquery is so cool.

  208. crusher website on August 5th, 2010

    Thank you for your share! I attempted to change the size of the containers to have it auto adjust, however that has not worked

  209. vertical roller mill on August 6th, 2010

    If you want to reverse the order, your going to have to set the default list style to have the thumbs first, and in your jquery, your going to addClass your list style to the thumb layout. Also don’t forget to change the css sprites on the button as well~

  210. mill on August 7th, 2010

    Great! It’s good and useful!

  211. stone crusher on August 10th, 2010

    Thank you for your share.very useful.

  212. Josh on August 10th, 2010

    Hello,

    I’m trying to implement your display switch in reverse. I want the thumbnails to show first. It’s working fine in FireFox and Chrome, but in IE6,7, and 8 it loads correctly at first but if I stitch to the list view and then back to the thumbnail view it messes up. It displays with only one or two thumbnails on each row instead of three.

    Any ideas as to what could be causing this?

    Thanks,
    Josh

  213. العاب on August 11th, 2010

    it’s so nice i use it in my site
    thank you

  214. pulverizer on August 11th, 2010

    I’m studying Jquery! Thank you!

  215. Shahid on August 12th, 2010

    Nice!

    Keep up the good work.

  216. crusher machine on August 14th, 2010

    Thank you! I use the first!

  217. cheap ghd on August 17th, 2010

    A bad beginning makes a bad ending.

  218. Aman on August 18th, 2010

    Hi

    I like this plugin.I have Also 10+ Jquery Style Switchers plugins please see:-

    http://jquery13.blogspot.com/2010/08/10-jquery-style-switchers.html

    Thanks
    Aman

  219. Josh on August 19th, 2010

    Could someone help me with the code I would need to make it so when the toggle button is clicked a variable’s value is changed at the same time? I want to use the variable to make the image change when the layout is toggled, unless someone has a better way.

    Thanks,
    Josh

  220. symons cone crusher on August 20th, 2010

    Thank you for sharing your link with us.

  221. Julien on August 25th, 2010

    Great tut’ as always. Thanks for sharing.

  222. grinding mill on August 31st, 2010

    great.thanks for share.