question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I use the index of this image carousel to return the actual image?

See original GitHub issue

I’ve been trying for a few days to select the center image (or current image) in my carousel. Once selected, I’d like to display the same image in a center-of-screen view-port; think scrolling through photo previews while the current photo is in a larger display. As you scroll, the center image is dynamically changing so the view port will too.

Here is my HTML where I’m trying to propogate said carousel image; the view port:

<div class="col-md-6" style="height:480px;border:1px solid #fff">
     <div id="view-port">
     </div>
</div>

The closest I’ve gotten to something successful is:

window.onload = function() {
    var centerSlide = document.createElement("img");
    centerSlide.src = $('#myCarousel').slick('slickCurrentSlide');
    document.getElementById("view-port").appendChild(centerSlide);
    console.log(centerSlide);
};

Which logs

<img src="0"> as expected, the index of the currentSlide. This can be observed here:

https://jsfiddle.net/positivecharge8/nddaj84x/

But I can’t figure out how to get the image so I can reference it to put into a div. I understand that the code that I have now won’t dynamically change the view port div image as I scroll through the carousel- that’s okay, for now I’d like to at least get some image up there. Thanks!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
BretMishlercommented, Feb 24, 2016

You did, thank you :] Any tips or hints on why a user should consider using your solution over the one I posted? Not at all trying to challenge your authority; you’ve contributed a lot to Slick and I’ve seen your solutions on many posts.

I’m not looking for you to prove yourself, but instead to share some wisdom. I’m a new JS/jQuery dev. Thanks man!

1reaction
simeydotmecommented, Feb 24, 2016

Please ask support questions in support channels. (read the contributing guidelines.)

var n = $('#myCarousel').slick("slickCurrentSlide");
var img = $('#myCarousel').slick("getSlick").$slides.eq( n ).children("img").attr("src");
Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - How can I use the index of this image carousel to ...
Using $('#myCarousel').slick('slickCurrentSlide'); gets you the index of the current image not the src of the image.
Read more >
react-native-image-slider-box - npm
Start using react-native-image-slider-box in your project by running `npm i ... callback for get current image index (index start from 0).
Read more >
Add a Responsive Image Carousel to Your React App
We'll see how to use the react-responsive-carousel package to add a responsive and customizable slider to a react app.
Read more >
Carousel - Bootstrap
A slideshow component for cycling through elements—images or slides of text—like a ... especially if you're using multiple carousels on a single page....
Read more >
React Bootstrap Carousel Component
A slideshow component for cycling through elements—images or slides of text—like a carousel. Example#. Carousels don't automatically normalize slide dimensions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found