Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lookahead loading with random order [SOLVED] #845

Open
panablue opened this issue Dec 19, 2019 · 0 comments
Open

Lookahead loading with random order [SOLVED] #845

panablue opened this issue Dec 19, 2019 · 0 comments

Comments

@panablue
Copy link

In case it's useful to anyone:

For non-random lookahead rotators I've found that at least the first 2 slide images have to be marked up normally (without the data-cycle-src attribute), however this doesn't work with the random option since it isn't known which slides will appear first.

Adding this snippet (updating the selector as needed) within the lookahead loading plugin loads the first two of the randomized slide images immediately:

// other plugin stuff above...
$(document).on( 'cycle-initialized', function(e, opts) {


// load first 2 images after randomizing
    var firstimages = document.querySelectorAll('.cycle-slideshow li:nth-child(-n+2) img[data-cycle-src]');
    for (var i = 0; i < firstimages.length; i++) {
        firstimages[i].src = firstimages[i].dataset.cycleSrc;
        firstimages[i].removeAttribute('data-src');
    }


var key = 'cycle-look-ahead';
// other plugin stuff below...

Note that using an appropriately-sized placeholder src image and height/width attributes avoids potential issues with autoheight, centering and reflow:

<img src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20WIDTHGOESHERE%20HEIGHTGOESHERE'%3E%3C/svg%3E" data-cycle-src="REALIMAGEPATH" width="WIDTHGOESHERE" height="HEIGHTGOESHERE" alt="">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant