简体   繁体   English

显示/隐藏幻灯片的标题仅适用于第一张幻灯片

[英]Show / Hide slide's title works only in first Slide

I am using a simple jQuery method to show/hide titles in Slick Slider.我正在使用简单的 jQuery 方法在 Slick Slider 中显示/隐藏标题。 But for some reason it only works for the first slide.但出于某种原因,它只适用于第一张幻灯片。

function myFunction() {
var x = document.getElementById("show");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
}

Also adding a class child, only works in first slide too:还添加一个班级孩子,也只适用于第一张幻灯片:

function myFunction() {
var x = document.getElementById("show");
var y = x.getElementsByClassName("slide");
var i;
for (i = 0; i < y.length; i++) {
y[i].style.display = "block";
}
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
}

Here is what I have:这是我所拥有的:

                 <section id="home-slider">
                 <div class="slick preloading">
                 <?php foreach ( $sliders as $i => $post ) {setup_postdata( $post );                    
                 $my_box = get_post_meta( $post->ID, '_format_video_embed_box', true ); ?>
                 <div class="slide">
                     <div class="video">
                        <div class="screen" id="slick-video-<?php echo my_wrap( $post->ID ); ?>"></div>
                     </div>
                 <div class="bottom">
                 <div class="sub">
                 <?php if ( my_mod( 'slider_layout' ) == 'full' ) { ?>                                  
                 <div class="container">                                    
                 <?php } ?>

<div class="inner">
<button onclick="myFunction()"> Click </button>
<div id="show">

                 <div class="post-author">
                 <?php the_author_posts_link(); ?><a href="<?php the_permalink() ?>"><h3><?php the_title(); ?</h3</a> 
                 </div>
                 <?php if ( my_mod( 'slider_layout' ) == 'full' ) { ?>
                 </div>             

<script>
function myFunction() {
var x = document.getElementById("show");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
}</script>
            </div>

                 <?php } ?>
                 </div>
                 </div>
                 </div>
                 </div>
                 <?php } ?>
                 </div>
                 </section>

CSS: CSS:

#show{
display:none;
}

How can I achieve to show/hide Titles for all slides or如何实现显示/隐藏所有幻灯片的标题或
show/hide titles for each slide with a simple jQuery method.使用简单的 jQuery 方法显示/隐藏每张幻灯片的标题。

I sat down... I thought... and I figured it out "... instead of using javascript, why not just applying CSS to achieve my goal... so here it is and its working like a charm! All Slides show/hide with a mouse over.我坐下来......我想......我想通了“......而不是使用javascript,为什么不只是应用CSS来实现我的目标......所以它就在这里,它的工作就像一个魅力!所有幻灯片用鼠标悬停显示/隐藏。

.bottom {
width: 100%;
height: 0;
bottom: -205px;
text-align: left;
color: #FFF;
z-index: 100;
}
.sub {
-webkit-transform: translate(0, 37%);
transform: translate(0, 37%);
transition: all 1s cubic-bezier(0.86, 0, 0.07, 1);
opacity: 0;
}
.bottom .inner {
width: 47%;
height: 450px;
margin: 0 0 0 150px;
position: relative;
bottom: 450px;
}

Demo: Slider's title Show and Hide on mouse over演示:滑块的标题在鼠标悬停时显示和隐藏

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

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