我将滑块与中继器字段组合在一起。在中继器下面,我有两个子域。一个叫做“image”,另一个叫做“title”。
这个滑块有一个叫做“selected -item”的类,当一个图像被选中时,它会动态出现。(当这个类在图像上时,图像会改变它的大小)。
我如何定义当“selected-item”类出现在某个图像上时,图像的同一行中的“title”表单也会出现?
这是显示图像的代码:
<?php
// check if the repeater field has rows of data
$i = 1;
if( have_rows('carousel_images') ):
// loop through the rows use_cases_fields data
while ( have_rows('carousel_images') ) : the_row();
$title=get_sub_field('image_carousel_discription');
$image = get_sub_field('image_carousel1');
if( !empty($image) ):
// thumbnail
$thumb = $image;
?>
<li id="image11" data-row="<?php echo $i; ?>" > <a
href="#home"><img src="<?php echo $thumb ?>"/></a> </li>
<h3 id="h3-data" data-row="<?php echo $i; ?>"><?php echo $title ?>
</h3>
<?php $i++; ?>
<?php endif; ?>
<?php
endwhile;
endif;
?>
JS- "carousel on“将类"selected-item”添加到image。
carousel.on('itemSelected.sc', function (evt) {
var image1=
document.getElementById("image11").getAttribute("data-row");
var hdata = document.getElementById("h3-
data").getAttribute("data-row");
var hdata2= document.getElementById("h3-data").innerText;
if(image1==hdata){
document.getElementById("change_h2").innerHTML =hdata2;
}
https://stackoverflow.com/questions/47653650
复制