Consider the following example of a photo album.
The first page and last page of the album are half the size of the spread of the album. I set the attr('data-width')
and attr('data-width_correct')
for comparison
For Example -- checkImageDimesions()
//Define if first or last page
if($(this).is(':first-child') || $(this).is(':last-child'))
{
$(this).find('img').attr('data-height_correct' , maxHeight);
$(this).find('img').attr('data-width_correct' , maxWidth / 2);
} else{
$(this).find('img').attr('data-height_correct' , maxHeight);
$(this).find('img').attr('data-width_correct' , maxWidth);
}
This works as expected, updating the data- with the correct values. My next step is if the width > width_correct
I want to add a class of resize.
if($(this).find('img').data('width') > $(this).find('img').data('width_correct'))
{
$(this).addClass('resize');
}
The calling of this function happens on the success of jQuery .sortable(). On first sort this works correctly, however on subsequent sorts, the initial image that is not sized correctly retains the .resize
and any new image that would return false on width > width_correct
does not get assigned resize
Sortable
$("#sortable").sortable(
{
success: function(){checkImageDimension()}
}