[英]Dynamic image text overlay on particular image hover
I have multiple dynamic images. 我有多个动态图像。 When I hover on a particular image it should show me read more button for that image.
当我将鼠标悬停在特定图像上时,应该向我显示该图像的更多按钮。 But currently from my code when I hover the image read more button it is displaying for all the images and when I am doing mouse out it remove all the read more button from the image .
但是目前从我的代码中,当我悬停图像阅读更多按钮时,它为所有图像显示,当我进行鼠标移出时,它从图像中移除所有阅读更多按钮。
Code is below: 代码如下:
echo '<div class="teacher-image"><img class="img-hover" src="';
the_field('teacher_image', $this_event);
echo '" alt="'; the_field('teacher_name', $this_event);echo '"></div>';
echo '<div class="teacher-link">';
echo"<a class='theme-button small-button purple-button popups' data-toggle='modal' data-target='#myModal-front' id='teacher-detail' href='javascript:void(0);' onclick='teacher_id($this_event);'>Read more</a>";
<script>
$(document).ready(function(){
$(".purple-button").css("opacity", 0);
$(".img-hover").mouseover(function(){
$(".purple-button").css("opacity",2);
});
$(".img-hover").mouseout(function(){
$(".purple-button").css("opacity",0);
});
$(".purple-button").hover(function() {
$(this).css("opacity",2);
});
});
</script>
What I exactly want is when I mouseover a particular image it should show me read more button for that image instead of all images and on mouseout it should hide. 我真正想要的是,当我将鼠标悬停在特定图像上时,它应该向我显示该图像而不是所有图像的更多按钮,并且在鼠标移开时应该隐藏。
What I am doing wrong here. 我在这里做错了。 Please help me solve this.
请帮我解决这个问题。
You can do that with JS but its easier with CSS on the container Hover. 您可以使用JS做到这一点,但使用容器Hover上的CSS则更容易。
HTML 的HTML
<div class="image-container">
<img src="img.jpg" />
<a href="#">Read more</a>
</div>
CSS 的CSS
.image-container > a {
display: none;
}
.image-container:hover > a {
display: block;
}
If you really want to use JS 如果您真的想使用JS
HTML 的HTML
<div class="image-container">
<img src="img.jpg" />
<a href="#">Read more</a>
</div>
JS JS
$('.image-container').on('mouseenter',function() {
$('a', this).show();
});
$('.image-container').on('mouseleave',function() {
$('a', this).hide();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.