Theis_Aarlund Posted September 23, 2020 Share Posted September 23, 2020 Site URL: https://www.davai.squarespace.com Hi all I am having some issues with a HTML code, that is supposed to change a image to another when hovered above. To access the page, you might have to use the password "davai" I have tried multiple solutions, but finally found one that actually worked (on one of the entities...) You can find it in the second section under "Kompetencer". As you can see, it works on "adgangsudstyr" when you hover the mouse above the image, but it does not work on the wind turbine over "Vindmølleservice" or "Overfladebehandling" The code i have gone for is: <center> <img src="URL to still image” onmouseover="this.src=’GIF image to replace still image’" onmouseout="this.src=’URL to still image’"> </center> When the URL is added, it looks like this (this is the one added to the page) <center> <img src="https://images.squarespace-cdn.com/content/5f6873716e3d0466b9953dd9/1600854461689-UHACZYWZUG5CQPHJJLWV/icon-wind-turbine-service.png?content-type=image%2Fpng” onmouseover="this.src=’https://images.squarespace-cdn.com/content/5f6873716e3d0466b9953dd9/1600868753305-7LONEER0YHGEWO5QEBPT/Wind-turbine.gif?content-type=image%2Fgif’" onmouseout="this.src=’https://images.squarespace-cdn.com/content/5f6873716e3d0466b9953dd9/1600854461689-UHACZYWZUG5CQPHJJLWV/icon-wind-turbine-service.png?content-type=image%2Fpng’"> </center> You should be able to access the images through the links. Feel free to come up with alternate solutions, although i have tried out a few so far... Link to comment
rwp Posted September 23, 2020 Share Posted September 23, 2020 This is easier to do with CSS, use 2 image tags with different classes inside a div. <div class="imgSwap"> <img class="img1" src=""> <img class="img2" src=""> </div> .img2 { display: none; } .imgSwap:hover .img1 { display: none; } .imgSwap:hover .img2 { display: inherit; } Link to comment
Theis_Aarlund Posted September 23, 2020 Author Share Posted September 23, 2020 8 minutes ago, rwp said: .img2 { display: none; } .imgSwap:hover .img1 { display: none; } .imgSwap:hover .img2 { display: inherit; } I've just tried it out it seems that the first bit of CSS, just hides the image completely, before i can see if it changes on hover, please tell if i am wrong Link to comment
rwp Posted September 23, 2020 Share Posted September 23, 2020 It hides the moving image, then on hover it hides the static one and shows the moving one. You also don't need a class for each image, they can all use the same class names, because they are changed by hovering, it know which one you are working with. Link to comment
Theis_Aarlund Posted September 24, 2020 Author Share Posted September 24, 2020 Well, clearly something is wrong with me, or the page. i added this code: HTML: <div class="ImgSwap"> <img class="Img1" src="https://images.squarespace-cdn.com/content/5f6873716e3d0466b9953dd9/1600854461689-UHACZYWZUG5CQPHJJLWV/icon-wind-turbine-service.png?content-type=image%2Fpng"> <img class="Img2" src="https://images.squarespace-cdn.com/content/5f6873716e3d0466b9953dd9/1600868753305-7LONEER0YHGEWO5QEBPT/Wind-turbine.gif?content-type=image%2Fgif"> </div> CSS: .ImgSwap { display: none; } .ImgSwap:hover .Img1 { display: none; } .ImgSwap:hover .Img2 { display: inherit; } It still just shows nothing, not one nor the other Link to comment
rwp Posted September 24, 2020 Share Posted September 24, 2020 Your CSS is incorrect. You are hiding the div, not the animated image. .Img2 { display: none; } .ImgSwap:hover .Img1 { display: none; } .ImgSwap:hover .Img2 { display: inherit; } Link to comment
tuanphan Posted September 26, 2020 Share Posted September 26, 2020 On 9/24/2020 at 1:22 PM, Theis_Aarlund said: Well, clearly something is wrong with me, or the page. i added this code: Have you solved it yet? Email me if you have need any help (free, of course.). Answer within 24 hours. Or send to forum message Contact Customer Care - Learn CSS - Buy me a coffee (thank you!) Link to comment
Theis_Aarlund Posted September 28, 2020 Author Share Posted September 28, 2020 On 9/27/2020 at 12:27 AM, tuanphan said: Have you solved it yet? Yes, the solution that @rwp came up with worked out fine, once i found a mistyping of mine 🙂 Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.