owl carousel flashing on page load
Clash Royale CLAN TAG#URR8PPP
owl carousel flashing on page load
on this page
http://www.exclusivecard.co.uk/offers.php
I have several owl carousels running. You'll notice when you first load the page that all off the offers in the carousel flash at full width until the jquery kicks in and then resizes everything. Is there anyway to stop this? Ill post some of the code I'm using below
Html
<?php $k='1'; do ?>
<div id="owlslide<?php echo $k;?>">
<?php do ?>
<div class="owlItem ">
<-- some other stuff -->
</div>
<?php while();?>
</div>
<?php $i++; while();?>
Jquery (owl)
$(document).ready(function()
<?php $i='1'; do ?>
$("#owlslide<?php echo $i;?>").owlCarousel(
autoPlay: false, //Set AutoPlay to 3 seconds
paginationNumbers: true,
itemsCustom : [
[0, 1],
[450, 1],
[600, 2],
[700, 2],
[1000, 3],
[1200, 4],
[1400, 4],
[1600, 5]
],
//navigation:true,
// navigationText: [
// "<i class=' btn '>< Previous </i>",
// "<i class='btn '>Next ></i>"
// ],
);
<?php $i++; while($cara = mysql_fetch_assoc($catCara)); ?>
);
5 Answers
5
You can hide the carousel items with display: none;
in your CSS, then show them after the carousel has initialized by binding a handler to the initialized.owl.carousel event. I find it's best to combine it with a placeholder that has a loader gif to further reduce page jump.
display: none;
var carousel = $('#owlslide');
carousel.on(
'initialized.owl.carousel': function ()
carousel.find('.item').show();
carousel.find('.loading-placeholder').hide();
).owlCarousel(options);
Note that you have to bind the handler before you initialize the carousel.
$('.item').trigger('initialized.owl.carousel').show();
Welcome to Stackoverflow. Thank you for your answer to this question. To Improve this answer explain why this will solve the OP's problem and where in their example code they should put this. For more information about writing good answers, see stackoverflow.com/help/how-to-answer
– Peter Campbell
Apr 25 '16 at 14:36
If you are using OwlCarousel2, the plugin attaches the CSS class .owl-loaded
to the .owl-carousel
after it has finished rendering the carousel items. Simply set display: none
on the container and reset display: block
on the appended class.
.owl-loaded
.owl-carousel
display: none
display: block
i.e. In your CSS file:
.owl-carousel
display: none;
.owl-carousel.owl-loaded
display: block;
Just hide images on loading and will auto show when loading complete!
still not a best solution, but if you set the opacity to 0, it will work at some level and all the items will not be there on page load.
.owl-carousel:not(.owl-loaded)
opacity: 0;
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You can add some loader to page and just remove that after all jquery completes.
– Harsh Sanghani
Dec 2 '15 at 11:46