I have divided sm image into five different triangles. I'm trying to change an image's src
attribute value on hover, and show the hovered' image in the center square.
This is what I'm trying to do, but with SVGs: How to change an image source on hover?
.overlay {
background-image: url('https://picsum.photos/id/118/1000/800');
background-repeat: no-repeat;
background-size: cover;
}
.overlay use {
opacity: 0;
transition: all 0.4s linear;
}
.overlay use:hover {
opacity: 1;
}
.vr-head-tilt {
position: relative;
}
.big img {
width: 200px;
height: 200px;
object-fit: cover;
}
.overlay .vr-images1:hover~.big .default {
opacity: 0;
}
.overlay .vr-images1:hover~.big>img:nth-child(1) {
z-index: 5;
opacity: 1;
}
.overlay .vr-images2:hover~.big>img:nth-child(2) {
z-index: 5;
opacity: 1;
}
.overlay .vr-images3:hover~.big>img:nth-child(3) {
z-index: 5;
opacity: 1;
}
.overlay .vr-images4:hover~.big>img:nth-child(4) {
z-index: 5;
opacity: 1;
}
.overlay .vr-images5:hover~.big>img:nth-child(5) {
z-index: 5;
opacity: 1;
}
.big {
position: relative;
}
.big img {
position: absolute;
bottom: 0;
left: 50%;
transform: translate(-50%, 7%);
opacity: 0;
transition: .2s .1s ease-out;
}
.big .default {
opacity: 1;
}
<svg class="overlay" viewBox="0 0 200 100">
<defs>
<clipPath id='clip-1'>
<polygon points="0,100 100,100 0,50"/>
</clipPath>
<clipPath id='clip-2'>
<polygon points="0,50 100,100 50,00 0,0"/>
</clipPath>
<clipPath id='clip-3'>
<polygon points="100,100 50,00 150,0"/>
</clipPath>
<clipPath id='clip-4'>
<polygon points="100,100 200,50 200,0 150,0"/>
</clipPath>
<clipPath id='clip-5'>
<polygon points="100,100 200,100, 200,50"/>
</clipPath>
<image id="img" x="0" y="0" width="200" height="100" preserveAspectRatio="xMidYMid slice"
xlink:href="https://picsum.photos/id/1/1000/800" />
</defs>
<use xlink:href="#img" class="vr-images1" clip-path="url(#clip-1)"/>
<use xlink:href="#img" class="vr-images2" clip-path="url(#clip-2)"/>
<use xlink:href="#img" class="vr-images3" clip-path="url(#clip-3)"/>
<use xlink:href="#img" class="vr-images4" clip-path="url(#clip-4)"/>
<use xlink:href="#img" class="vr-images5" clip-path="url(#clip-5)"/>
</svg>
<div class="box"></div>
<div class='big'>
<img src="https://i.ibb.co/rxX8VMq/left.png" class='default'>
<img src="https://i.ibb.co/r77CrCC/topleft.png">
<img src="https://i.ibb.co/CzRdRtp/top.png">
<img src="https://i.ibb.co/L8cSs3p/topright.png">
<img src="https://i.ibb.co/D1cjqfD/right.png">
</div>
When we hover on each polygon, the center image should change.