I have tested the following codes on a normal HTML webpage with no problem. However, I can't get it work on a xaringan slide. xaringan is an R presentation template.
I am not sure if there is any limitation on xaringan.
.hover-title {
display: inline;
pointer-events: auto;
cursor: pointer;
}
.hover-image {
visibility: hidden;
}
body:not(.mobile) .hover-title:hover + .hover-image {
visibility: visible;
pointer-events: none;
}
.hover-image {
display: flex;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: -1;
pointer-events: none;
flex-direction: column;
align-items: center;
justify-content: center;
/* Change width and height to scale images */
width: 90vw;
height: 90vh;
}
.hover-image img {
max-width: 100% !important;
max-height: 100% !important;
width: auto !important;
height: auto !important;
margin-bottom: 0;
}
<div class = "hover-title">
Default Setting
</div>
<div class = "hover-image">
<img src="https://images.unsplash.com/photo-1486312338219-ce68d2c6f44d?w=752&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D" alt="">
</div>
You are not seeing the image on hover inside xaringan
because the hover-image
class has z-index
set to -1 and xaringan
slides are contained within a div with class remark-visible
which has z-index
set to 2.
So to show the image on hover you just need to increase the z-index
of hover-image
little more, say 5.
.hover-image {
display: flex;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 5; /* increased z index */
pointer-events: none;
flex-direction: column;
align-items: center;
justify-content: center;
/* Change width and height to scale images */
width: 90vw;
height: 90vh;
}