PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 26, 2022

[FIXED] masonry + isotope + imagesLoaded not defined yii

 January 26, 2022     javascript, jquery-isotope, masonry, yii, yii-extensions     No comments   

Issue

Hello i´m new to web development. I´m struggling with a JS function using Yii 1.1: isotope-jquery. Trying to show a masonry image gallery with infinite scrolling. If i leave it as it is it works, but when using images they get all overlapped at the end. i should use imagesLoaded, but applying it´s being a pain...

Original code:

 $defaultCallback="
        function( newElements ) { 
        /* hide new items while they are loading*/ 
        var newElems = jQuery( newElements ); 
        \$isoContainer.isotope( 'appended', newElems, true );
        {$this->infiniteCallback}
        }";

Modified:

function( newElements ) { 
        /* hide new items while they are loading*/ 
        var newElems = jQuery( newElements );
        \$newElems.imagesLoaded(function(){         
            \$isoContainer.masonry( 'insert', newElems);
        });
        {$this->infiniteCallback}
        }"

Error on browser console:

["math:", 222, 2853] jquery.infinitescroll.js:171
["math:", 0, 2853] jquery.infinitescroll.js:171
["heading into ajax", Array[2]] jquery.infinitescroll.js:171
["Using HTML via .load() method"] jquery.infinitescroll.js:171
["contentSelector", div.items.isotope] jquery.infinitescroll.js:171
Uncaught ReferenceError: $newElems is not defined index.php?r=products:112(anonymous function) index.php?r=products:112opts.callback jquery.infinitescroll.js:159infscr_loadcallback jquery.infinitescroll.js:327infscr_ajax_callback jquery.infinitescroll.js:501jQuery.extend.each jquery.js:595jQuery.fn.jQuery.each jquery.js:241jQuery.ajax.complete jquery.js:7465fire jquery.js:974self.fireWith jquery.js:1084done jquery.js:7818callback

i´ve tried several things, defining the var inside, passing parameters, but i cannot make it work...

probably it´s a newbie issue...

thanks for your help


Solution

So this is the solution, and works like a charm!

function( newElements ) { 
        /* hide new items while they are loading*/ 
        var newElems = jQuery( newElements );
        \$isoContainer.imagesLoaded(function(){         
        \$isoContainer.isotope( 'appended', newElems,true);
        });

thanks @Macsupport



Answered By - user4055746
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing