简体   繁体   English

如果我单击下一个/上一个,如何立即显示从轮播到第二个div的活动图像?

[英]How to display immediately an active image from carousel to my 2nd div if I click next/ previous?

I'm having problem displaying an active image from carousel to my 2nd div when I click next/ previous. 单击下一个/上一个时,我无法在轮播中显示活动图像到第二个div。 Looks like it's delayed when I click next/ previous. 当我单击下一个/上一个时,它似乎延迟了。

 function strapActiveImage() { var activeElImgSrc = document.querySelector('div#strap_carousel>div.carousel-inner>.carousel-item.active > img').getAttribute('src'); document.getElementById('strap_logo').src = activeElImgSrc; document.getElementById('strap_logo2').src = activeElImgSrc; } 
  <!-- STRAP --> <div class="justify-content-center body-inner"> <div class="personalize-item-title left-align bold"> <span>STRAP</span> </div> <!-- CarouselBegin --> <div id="strap_carousel" data-interval="false" class="carousel" data-ride="carousel"> <div class="carousel-inner"> <div class="carousel-item active"> <img src="stap_design/strap_1.png" class="personalize-left-strap margin-top"> </div> <div class="carousel-item"> <img src="stap_design/strap_2.png" class="personalize-left-strap margin-top"> </div> </div> <a class="carousel-control-prev" href="#strap_carousel" role="button" onclick="strapActiveImage()" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next" href="#strap_carousel" onclick="strapActiveImage()" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> <span>LEATHER</span> <!-- CarouselEnd--> </div> <!-- STRAP END --> <div class="justify-content-center body-inner"> <img src = "stap_design/strap_1.png" class="strap_display" id="strap_logo"> <img src="stap_design/strap_1.png" class="strap_display2" id="strap_logo2"> </div> 

For the benefit of those who are looking for an answer for a question/ problem like this one, I was able to solve my own problem by adding an onload="strapActiveImage()" to the image tag (where display is happening). 为了那些正在寻找诸如此类问题的答案的人的利益,我能够通过在图像标签上添加onload =“ strapActiveImage()”(正在显示的地方)来解决自己的问题。 Here is the code: 这是代码:

 function strapActiveImage() { var activeElImgSrc = document.querySelector('div#strap_carousel>div.carousel-inner>.carousel-item.active > img').getAttribute('src'); document.getElementById('strap_logo').src = activeElImgSrc; document.getElementById('strap_logo2').src = activeElImgSrc; } 
  <!-- STRAP --> <div class="justify-content-center body-inner"> <div class="personalize-item-title left-align bold"> <span>STRAP</span> </div> <!-- CarouselBegin --> <div id="strap_carousel" data-interval="false" class="carousel" data-ride="carousel"> <div class="carousel-inner"> <div class="carousel-item active"> <img src="stap_design/strap_1.png" class="personalize-left-strap margin-top"> </div> <div class="carousel-item"> <img src="stap_design/strap_2.png" class="personalize-left-strap margin-top"> </div> </div> <a class="carousel-control-prev" href="#strap_carousel" role="button" onclick="strapActiveImage()" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next" href="#strap_carousel" onclick="strapActiveImage()" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> <span>LEATHER</span> <!-- CarouselEnd--> </div> <!-- STRAP END --> <div class="justify-content-center body-inner"> <img src = "stap_design/strap_1.png" class="strap_display" id="strap_logo" onload="strapActiveImage()"> <img src="stap_design/strap_1.png" class="strap_display2" id="strap_logo2" onload="strapActiveImage()"> </div> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使twitter bootstrap 3轮播中心处于活动图像的中心,并显示下一张和上一张图像的一部分? - How can I make twitter bootstrap 3 carousel centre the active image and show part of the next and previous images? 第二张图像的 onclick 应该激活(即进行 next() 调用) - onclick of 2nd image should become active (i.e. make a next() call) 使用图像轮播中的下一个/上一个按钮重复单击 - Redundant click with next/previous buttons in image carousel Javascript-单击第二个按钮可清除我的div - Javascript - 2nd button click clears my div 我如何创建一个在单击下一个和上一个按钮时滑动的旋转木马,旋转木马应该切换 div 而不是图像 - how do i create a carousel that slides on next and previous button click, the carousel should switch divs and not images 如何在轮播中将上一个和下一个图像嵌入上一个和下一个按钮 - How to embed the previous and next image in the previous and next button in a carousel 如何使图像轮播控件“下一个”和“上一个” - How to make Image Carousel Controls 'next' and 'previous' 单击引导轮播中的下一个或上一个时,图像会跳转 - Image jumps when click on next or previous on bootstrap carousel 单击下一个/上一个图像滑块/转盘运行不流畅? - Image slider/carousel not running smoothly when click next/previous? 具有下一个和上一个显示的无限轮播 - Infinite Carousel with next and previous display
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM