Search code examples
jquerycallbackonloadjcrop

Run function after Jcrop has finished loading (solution)


This is not a question, just a tip after trying to get this to work myself. Maybe people know about it already but I found no documentation of it (on the Jcrop site or elsewhere).

This is actually just an undocumented feature, looking at the source code for Jcrop I noticed that it accepted a function as a second argument after the settings, which gets called after Jcrop has finished loading. So just enter your function there and presto!

  $('#imagetocrop')
    .Jcrop(
      {
        /* settings go here */
      },
      function() { alert('Jcrop has finished loading!) });

Note: The settings object is NOT optional in this case. the callback only works as a second argument. You can send an empty settings object { } and it works just fine, but why you'd need a callback for such a simple Jcrop function is beyond me...

Happy coding!


Solution

  •  $('#imagetocrop').Jcrop(
       {
         /* settings go here */
       },
       function() 
       { 
         alert('Jcrop has finished loading!) 
       });