Search code examples
javascriptjqueryhtmlcsscentering

jQuery animate after resize


I'm using jQuery Image Center plugin and trying to animate image after it is centered

here is my code, image centering works but animation doesn't

$('#myimage').css('opacity' , 0);
$('#myimage').centerImage(function() {
  //At this point, resize is complete, and the element is invisible
  $(this).animate({opacity: 1}, 1500 );
});

Solution

  • According to the plugin source, second argument is the callback and first one method of centering. So try

    var $img =$('#myimage');
    $img.css('opacity', 0);
    
    $img.centerImage('inside', function () { //give inside or for no method just provide undefined or ""
          //At this point, resize is complete, and the element is invisible
        $(this).animate({
            opacity: 1
        }, 1500);
    });
    

    Demo

    Demo2

    Also remember you can chain em through as in the demo.