简体   繁体   中英

How to embed the previous and next image in the previous and next button in a carousel

I am making a portfolio website, with a carousel to showcase my images. I have successfully coded the carousel to work. Now, I just have one obstacle: I want the 'Next' and 'Prev' button to show the next and previous image. What kind of javascript code, would I have to put inside of my code, in order for this to work? This image illustrates what I mean

Find whatever functions are being called for you normal carousel next and prev buttons and call them from your next and prev images by adding an onclick attribute to them in the html.

<img inclick="prevImage()" href="image1"
<!-- Main carousel image -->
<img onclick="nextImage()" href="image3">

You could then just swap the hrefs of the images. Alternatively, you could create an array of images and have a prev, current, and next classes. Style those using CSS and still onClick would just be updating the classes.

Some more detail could better guide a better response.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM