"Enhancing the appearance of sorted divs using CSS3 animations in jQuery

Looking to enhance the sorting functionality of divs using jQuery by incorporating CSS3 transition animations for smoother transitions.

Encountering an issue where the CSS3 transition animation is not functioning as expected, currently investigating the root cause:

Example for reference: jsFiddle

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<title>Testing Sort with Animation</title> 
<link rel='stylesheet' href='http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css' type='text/css' media='screen' />
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.js'></script>
<script type='text/javascript' src='http://code.jquery.com/ui/1.9.2/jquery-ui.js'></script>
<style>
.gallery {
  background-color: black;
}

.imgitem {
  width: 40px;
  height: 40px;
  background-color: blue;
  margin-bottom: 10px;
  overflow: hidden;
  background-color: blue;
  position: relative;
}

.imgitem {
  -webkit-transition: all 1s ease-in-out;
  -moz-transition: all 1s ease-in-out;
  -o-transition: all 1s ease-in-out;
  transition: all 1s ease-in-out;
}
</style>
</head> 
<body>
<button id="chrank">Sort Items</button>
<div class="gallery">
  <div class="imgitem" style="background-color: red;"><div class="pop">6</div></div>
  <div class="imgitem" style="background-color: blue;"><div class="pop">4</div></div>
  <div class="imgitem" style="background-color: green;"><div class="pop">8</div></div>
  <div class="imgitem" style="background-color: brown;"><div class="pop">1</div></div>
  <div class="imgitem" style="background-color: magenta;"><div class="pop">3</div></div>
  <div class="imgitem" style="background-color: grey;"><div class="pop">5</div></div>
  <div class="imgitem" style="background-color: pink;"><div class="pop">4</div></div>
  <div class="imgitem" style="background-color: navy;"><div class="pop">7</div></div>
  <div class="imgitem" style="background-color: yellow;"><div class="pop">9</div></div>
</div>

<script>
    $('.gallery').sortable({ disable: true });

    function doSort()
    {
        $('.gallery').sortable({ disable: true });
        $('.gallery').sortable('refresh');
        $('.gallery .imgitem').sort(sortAscending).appendTo('.gallery');
    }

    function sortAscending(a, b) {
        return $(a).find(".pop").text() > $(b).find(".pop").text() ? 1 : -1;
    };

    $("#chrank").live("click", function(){
      doSort();
    });
</script>

</body> 
</html>

Answer №1

Initially, CSS transitions are effective. By inspecting the .imgitem Element in dev tools and applying a CSS position attribute (such as

style="position: relative, top: 20px"
), you will observe that transitions are functioning smoothly.

I believe the reason why there is no impact on the dvi.gallery is because the doSort() function does not alter the actual position of the element. Instead, it organizes all elements in ascending order and then displays the sorted collection within the dvi.gallery.

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

Is it possible to caution users before refreshing the page, while still allowing them to

I have a script that displays a warning message to the user when they attempt to refresh the page. It works perfectly for that purpose. However, my issue is that this same alert pops up when a user clicks on a button or a link within the website itself. I ...

What is the best way to reduce the font size on a

I've been applying the following CSS: .text_style3{ font:normal 8px Helvetica; color:#f7922c; } I'm trying to decrease the size further, but anything below 10px doesn't seem to work. I've attempted using 7px, 6px, 5px, etc., w ...

Delay problem caused by setTimeout

I am developing a version of the "Game of Life" using javascript. I have successfully implemented all the logic within a function named doGeneration(). When calling this function repetitively from the console, everything works as expected. However, when at ...

Guide to making a single row beneath two columns using CSS Grid

My goal is to utilize CSS Grid in order to design a blurb layout featuring 2 columns at the top and a full row below. This will allow for an FA Icon and Title, accompanied by a full description below, similar to the image provided. I believe I have succes ...

"Ascend beyond the constraints of fixed measurements with dynamic

My JQuery image fader has a width of 100% and height set to auto. I'm thrilled that it works perfectly on the iPhone as well. Now, I am facing a challenge while trying to make content "float" after my JQuery slider. The problem arises because I use ...

The outer border of the Angular Material Mat Grid List is beautifully highlighted

In my project, I have a mat grid list where users can define the number of rows and columns. My goal is to display borders around each mat-grid-title cell. However, I am struggling to properly display the outermost black border for the entire mat-grid-lis ...

Expanding Viewports with Dynamic Scrolling Bootstrap Columns

Striving to achieve a specific design in Bootstrap, but hitting roadblocks. The criteria are as follows: No scrolling in the browser window. Display occupying 100% of browser height. Columns for Menu, Left contents, and Right contents must scroll indepen ...

I'm struggling to make my div display inline

My div elements are not displaying inline, I'm thinking maybe I shouldn't use the nav and div structure like this. But starting over again seems like a lot of work. How can I fix this issue? Just so you know, I'm only on my 4th day of learn ...

Show a picture outside of the dropdown container

I'm currently navigating the world of web development and I'm facing a challenge with getting an image to display outside of a dropdown div. Despite numerous attempts at setting the image's position to relative, with overflow-visible, I have ...

Is there a more efficient method for performing multiple JavaScript replace calls rather than executing them individually?

In my Javascript code, I am creating a string that includes HTML content. Currently, my approach involves the following steps: var filter = ""; filter = util.getTemplate( "tmp_filter", temps ); filter = filter.replace( 'id="tmp_filter"','& ...

Footer division misbehaving

My goal is to add a footer to my website that includes a text field, but for some reason I'm encountering an issue with two of my divs not cooperating. You can observe this problem in this JSFiddle. Here is the CSS code for the footer: .footer { b ...

Click on the entire table to be redirected to the specified link

Currently, I am facing an issue with styling my tables as links. I have 3 tables and I want each table to be a clickable link. However, after implementing the links, I am unable round the corners of the tables. I envision the final look to be similar to t ...

I've been attempting to access the Marketo API, but unfortunately, I haven't had any luck

I've been attempting to make a Marketo API call, but I keep encountering this issue: net::ERR_NAME_NOT_RESOLVED Here is the code snippet I'm using for the function: var marketoAPIcallURL = 'https://182-EMG-811.mktorest.com/rest/v1/ ...

Using Multiple SCSS Files to Reference a Centralized Style Sheet

I am currently developing a React application and facing an issue with my SCSS files. I have three SCSS files, one main file that contains theme variable colors, and the other two are located in component folders. When I import the main SCSS file into the ...

Unforeseeable actions of Bootstrap-datepicker

I'm currently utilizing bootstrap-datepicker from the uxsolutions collection on GitHub and I've encountered some unusual behavior. At times, it loads properly while other times it does not: https://i.stack.imgur.com/mAVAc.png When it loads corr ...

Stop cascading styles when using nested rules in LESS to prevent unintended style application

In the process of developing a sophisticated front-end system using plugins, we are exploring different methods for composing CSS rules. Currently, we are considering two main approaches: Including parents in the class name Nesting parents in the selecto ...

Prevent jQuery from overriding CSS styling

Having an issue with adding a <p> tag before each jQuery accordion on my MVC page. No matter what I try, the jQuery styling keeps interfering with the classes and styles of my <p> tag. Is there a way to make it look like the other non-jQuery & ...

Encountering an "Angularjs 1.2.x Injector:modulerrr" error, even after successfully incorporating ngRoute

I am currently learning angularjs and I have encountered a persistent error. Despite multiple attempts at troubleshooting, I have been unable to resolve it. Here is the code that I have: index.html <!doctype html> <html ng-app="myApp"> <he ...

Performing both an insertion and an update operation on separate tables simultaneously within a single

I have designed a form with an input field that features autocomplete functionality, while the other input field is set as readonly. <div id="windowContent"> <form action="rdpw_monitoring_process.php" method="post"> <tab ...

Can you generate a new element based on a template element?

I'm encountering an issue with the following code snippet: template = $("#template"); $(template).attr("id", "newid"); $(template).appendTo("body"); My goal is to assign an id to the template and then modify its content. However, I seem to be direc ...