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

Owl Carousel is not working on adding images to it dynamically. #2446

Closed
MayankValechha opened this issue Sep 19, 2018 · 2 comments
Closed

Comments

@MayankValechha
Copy link

MayankValechha commented Sep 19, 2018

Currently I'm working on a small eCommerce project, I'm using Parse Server in Back4app.com.

I'm using Owl Carousel for showing the images. When I manually add images in a .owl-carousel class It is working fine.

But when I add images to the .owl-carousel class from my Parse Server, It is not showing that Images in a Carousel,

I am using vanilla JavaScript to create elements and show in a div.
Here is my HTML Code -

<div id="ads" class="owl-carousel">
 
</div>

Here is my JS Code -

let output = '';
var query = new Parse.Query('Offers');
query.find().then(function(result){
     for(let a in result){
     output += 
           '<img src="'+result[a].get('offerImage').url()+'">';
       }
        document.getElementById('ads').innerHTML = output; 
});

error

Output Images is also attached, you can see that above all the images are inside a .owl-carousel class.
Any Help on this topic will be appreciable.
Thanks!

@keefyhub
Copy link
Contributor

keefyhub commented Sep 21, 2018

I think this is because the carousel is being initialised before the images are loaded. If you can trigger a refresh after the images have been inserted it should work

$('#ads').trigger('refresh.owl.carousel');

or only initialise the carousel after your image query has finished

@MayankValechha
Copy link
Author

@keefyhub I tried this refreshing approach in a different way and it worked for me!
Thanks! <3

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

2 participants