0

How do i activate JS and other jquery functions, like masonry after the page is loaded.

i use:

jQuery("#filterbox").load("mypage.html"}); works fine, but eg. mansory is not activated.
jQuery('#content #boxes').masonry({ columnWidth: 122, animate: true });

but the second is not "activated".

is it correct that css, and js is not activated during .load, and if, how do i activate it afterward.

Thanks for any help..

/regards

1

4 Answers 4

3

Try this:

jQuery("#filterbox").load("mypage.html", function(){
   $('#content #boxes').masonry({ columnWidth: 122, animate: true });
});

By the way, you have an extra } after mypage.html.

3

Since jQuery.load is asynchronous, jQuery('#content #boxes').masonry will run DIRECTLY after the call to jQuery.load. You need a way to tell jQuery that you want to execute that function after the content actually has been loaded.

jQuery.load takes a callback function as the second argument. This callback will execute after your content has loaded. Try this:

jQuery("#filterbox").load("mypage.html", function() {
    jQuery('#content #boxes').masonry({ columnWidth: 122, animate: true });
});

Go ahead and read the documentation for .load().

1
  • Perfect!! Thank you so much. i have struggled with this for days.
    – user625079
    Apr 3, 2011 at 20:11
0

Try this

jQuery("#filterbox").load("mypage.html",function() {
      jQuery('#content #boxes').masonry({ columnWidth: 122, animate: true });
    });
0

Add a ImagesLoaded script https://github.com/desandro/imagesloaded/blob/master/imagesloaded.js

Try:

jQuery("#filterbox").load("mypage.html",function() {
    jQuery('#content').imagesLoaded(function() {
        jQuery(this).masonry({ itemSelector: '.box' });
    });
});

It works for me, hope this helps you too

my example (choose gallery in navigation): http://test.crystalstudio.me/nms/

1
  • .box - change this to Your selector Jun 19, 2013 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.