Sleek customizable collection showcase

I need to make some adjustments to this filterable portfolio. Specifically, the transitions are not as smooth as I would like.

JS

var Portfolio = {
    sort: function(items) {
        items.show();
        $('#portfolio-content').find('div.portfolio-item').not(items).fadeOut(500);
    },
    showAll: function(items) {
        items.fadeIn(500);
    },
    doSort: function() {
        $('a', '#portfolio-sort').on('click', function() {

            var $a = $(this);
            if (!$a.is('#all')) {

                var items = $('div[data-cat=' + $a.data('cat') + ']', '#portfolio-content');

                Portfolio.sort(items);

            } else {

                Portfolio.showAll($('div.portfolio-item', '#portfolio-content'));


            }

        });
    }
};

Portfolio.doSort();

HTML

<div id="portfolio">
<div id="portfolio-sort">
    <a href="#" id="all">ALL</a>
    <a href="#" data-cat="a">A</a>
    <a href="#" data-cat="b">B</a>
    <a href="#" data-cat="c">C</a>
</div>
<div id="portfolio-content">
    <div class="portfolio-item" data-cat="a">A</div>
    <div class="portfolio-item" data-cat="b">B</div>
    <div class="portfolio-item" data-cat="c">C</div>
    <div class="portfolio-item" data-cat="c">C</div>
    <div class="portfolio-item" data-cat="b">B</div>
    <div class="portfolio-item" data-cat="a">A</div>
    <div class="portfolio-item" data-cat="a">A</div>
    <div class="portfolio-item" data-cat="c">C</div>
    <div class="portfolio-item" data-cat="b">B</div>
</div>

CSS

#portfolio {
    width: 100%;
    max-width: 600px;
    margin: 2em auto;
}

#portfolio-sort {
    text-align: center;
    padding-bottom: 3px;
    border-bottom: 1px solid #999;
    margin-bottom: 1em;
}

#portfolio-sort a {
    color: #fff;
    background: #a00;
    display: inline-block;
    padding: 3px 9px;
    text-decoration: none;
    margin-right: 1em;
}

#portfolio-content {
    overflow: hidden;
}

div.portfolio-item {
    float: left;
    margin: 0 3% 1em 0;
    width: 29%;
    height: 10em;
    line-height: 10;
    text-align: center;
}

div[data-cat="a"] {
    background: #ccc;
}

div[data-cat="b"] {
    background: #666;
    color: #fff;
}

div[data-cat="c"] {
    background: #333;
    color: #fff;
}

Would it be possible to enhance the filtering effect using CSS3 or jQuery for smoother transitions?

For the full code, please visit: http://jsfiddle.net/gabrieleromanato/KkxyS/

Answer №1

I have implemented some modifications to your JavaScript code:

var Gallery = {
    filter: function (items) {
        Gallery.hideAll($('#gallery-content *'));
        Gallery.showFiltered(items);
    },
    showFiltered: function (items) {
        items.fadeIn(700);
    },
    hideAll: function (items) {
        items.hide();
    },
    applyFilter: function () {
        $('a', '#filter-gallery').on('click', function () {
            var $a = $(this);
            if (!$a.is('#all')) {
                var items = $('div[data-category=' + $a.data('category') + ']', '#gallery-content');
                Gallery.filter(items);
            } else {
                var items = $('#gallery-content *');
                Gallery.hideAll(items);
                Gallery.showFiltered(items);
            }
        });
    }
};

Gallery.applyFilter();

You can view the updated code on jsfiddle here: http://jsfiddle.net/KkxyS/56/

I hope these changes work well for you.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to remove the selected option value using Jquery

I have encountered an issue with clearing the select option value dynamically using Jquery in my code. Below is a brief explanation of the setup: report.php: <div class="col-sm-4"> <select class="form-control selectized" data-live-search="true" ...

What is the correct way to integrate $.deferred with non-observable functions?

Imagine you have two functions filled with random code and the time they take to complete is unknown, depending on the user's system speed. In this scenario, using setTimeout to fire function2 only after function1 finishes is not practical. How can j ...

Encountering a syntax error when utilizing a specific JavaScript method

I encountered an error while working on my JavaScript code. I am trying to prevent duplicate values using a method, but it is resulting in a syntax error. Let me explain the relevant part of the code below: var outputList = []; for (var i = 0; i < spec ...

unusual problem with referencing jQuery mobile pages and implementing click functionality

I am facing a strange issue with my index.html page, which is a website built using jQuery Mobile. The problem arises when I click on a button multiple times within a form on this page - it generates an alert to confirm that the button is working and then ...

Adjust the size of the logo as the user scrolls

Currently, I am implementing a JavaScript feature that allows my logo to shrink when the user scrolls down and grow when they scroll up. To achieve this effect, I am utilizing the jQuery functions addClass and removeClass. However, I have encountered som ...

creating interconnections between input fields by employing event listeners in JavaScript

I've been experimenting with binding multiple input fields to a span element using jQuery. Specifically, I have two input fields containing integer values and the sum of these values is displayed in a span element. I want the span element to update wh ...

Expansive image coverage

My footer design includes a rounded left image, a repeating middle section, and a rounded right image. How can I ensure that it scales perfectly responsively without overlapping? Ideally, the solution would involve adjusting the width of the middle section ...

Using PHP to detect changes in input fields upon page load with jQuery

I have a jQuery snippet on my page: $( document ).ready(function() { $("#URL").on("input load", function(e) { console.log(e.type) .... }); }); Further down the page, I also have... <input id="URL" type="text" value="<?=$_GE ...

Determining the screen width of mobile devices across the board

While using the Google Chrome inspector to simulate the Galaxy S5 (360px) screen, I am encountering issues with detecting the correct screen width. The CSS for 360px is being overridden by the 768px CSS instead. Is there a more effective solution to this ...

What is causing the slider image to be the only element that is not adapting to different screen sizes?

I am currently using the flexslider from woothemes and I am unable to understand why the image is consistently wider than the content when the browser window is resized or when viewed on an iPad/iPhone. Upon inspection, I couldn't find any styles on ...

How to send a complex object containing a Dictionary to an MVC controller action using JQuery

Question: I have a model with a Dictionary type field that needs to be posted to the backend controller action. How should I define the model object in JQuery? I keep encountering a primitive error from the ajax call with the code below: var templateBuil ...

Is it possible to include jQuery's selectors contain and closest within my CSS selector?

I created a script to hide specific table rows as follows: $('.ms-formtable nobr:contains("Question")').closest('tr').hide(); However, I'm unsure if there is a way to achieve the same result using only CSS. Can anyone provide adv ...

Troubleshooting Problem with CSS3 Transition Rotation

Can someone help me with my CSS3 transitions issue? I'm working on a new website and trying to rotate some images. It's working fine in a new HTML document, but when I try to add it to my actual website, nothing happens. Any advice or tips would ...

Exploring jQuery AJAX Attributes during ajaxStart and ajaxStop event handlers

With my project consisting of over 40 ajax webservice calls, I am looking to incorporate additional debugging features. One such feature is a timing method which I have already developed using my Timer class/object in Javascript. I'm seeking assistan ...

Is there a way for me to display both the right and wrong answers in real-time as users make their selections on my multiple-choice question website? Additionally, can I track the number

I've just implemented the code for my multiple-choice question (MCQ) website. One of the key features I want to include is immediate feedback when a user selects an answer - indicating whether it is correct or incorrect along with showcasing the corre ...

Discovering and choosing the appropriate course

I am facing a situation where I need to specifically select an element with the class .foo, but there are two anchor tags, both having the class .foo. However, I only want to select the one without the additional .bar class. How can I achieve this? <a ...

Updating Jquery Datepicker with Dropdown Selection

With a dropdown menu and JQuery UI Date Picker, I am trying to set a specific function. Let's say the dropdown has options for Sunday and Monday. If I select Sunday from the dropdown, I want all Sundays to be disabled in the calendar. On the other han ...

The background banner is failing to display within the divbox

Having some trouble with my top banner in the HTML and CSS code I'm using to create a master page for ASP.NET. Oddly, the banner does show up on the design tab in Visual Studio, but it's not displaying properly. Here's the relevant code, can ...

I am experiencing issues with the HTML footer not displaying correctly on my website

My GitHub Pages hosted website is giving me trouble with the footer styling. No matter what I try, I can't seem to get the background color to show up: h1 { background-color: #000000; } I'm attempting to create a footer similar to the one at ...

Is it possible for Firebug to display CSS comments? This feature would greatly assist in utilizing SASS

Can Firebug display CSS comments? I'm wondering if it can help with debugging when using line numbers from SASS. I haven't been able to find any information on this feature, so any help would be greatly appreciated. ...