run javascript after image is lazyloaded

lukasildza's Avatar

lukasildza

11 Nov, 2017 02:50 PM

Hi.
Im using slider with lazyload enabled here - http://www.lukasildza.sk/wp/
To make images always fill the screen and keep aspect ratio, im using this script lower, to check if the windows aspect ratio is wider or narrower than particular image, and then add a class accordingly. Problem is, that it only works for images which are loaded on the beginning.
Could you please help me, how to fire this script also when new image is added? i believe it is documented but i cant really use it. Im not a coder. Would be much appreciated :)

$j(window).load(function() {
function resizeBg() {

    if ( ($j(window).width() / $j(window).height()) < $j("body.home img.rsImg").width() / $j("body.home img.rsImg").height()) {
        $j("body.home img.rsImg")
            .removeClass('rs-homeslider-width')
            .addClass('rs-homeslider-height');
    } else {
        $j("body.home img.rsImg")
            .removeClass('rs-homeslider-height')
            .addClass('rs-homeslider-width');
    }                   
}   

$j(window).resize(resizeBg).trigger("resize");

});

  1. Support Staff 1 Posted by Dmitry Semenov on 11 Nov, 2017 05:24 PM

    Dmitry Semenov's Avatar

    Hello,

    You may use rsAfterContentSet event http://help.dimsemenov.com/kb/wordpress-royalslider-advanced/wp-whe...

    But I wonder why you don't want to just use fill scale mode http://help.dimsemenov.com/kb/royalslider-jquery-plugin-faq/how-to-...

    Dmitry

  2. 2 Posted by lukasildza on 12 Nov, 2017 07:56 AM

    lukasildza's Avatar

    Hello,
    thanks for quick help. For some reason, when i tried fill scale mode with centering earlier, it was not working as expected. Tried to disable my .js code now and enable it, and it's working like a charm.

    Thanks!

  3. lukasildza closed this discussion on 12 Nov, 2017 12:16 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac