The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

How can I add another image, when hovering this image?

3 posters

Go down

Solved How can I add another image, when hovering this image?

Post by Friendly Toucan February 8th 2023, 11:31 am

Hello,

Look at this code:

Code:
<a target="_blank" href="My URL . com"><img style="width: 250px; height: 100px;" alt="" border="0" src="My IMG URL . png" /></a>
(I have not decided what links to use yet. But first one is the page visited when clicking, and second one is the image displayed that you click on.)

How can I make it so that when you hover the image, it turns into another image? It needs to light up, in the same way a regular link would.

Edit: The second image should be the same size as the first one, 250×100.

Thanks.


Last edited by Friendly Toucan on February 8th 2023, 12:39 pm; edited 1 time in total
Friendly Toucan
Friendly Toucan
Forumember

Posts : 243
Reputation : 4
Language : English

https://cerulean-blues.forumotion.com

Back to top Go down

Solved Re: How can I add another image, when hovering this image?

Post by Razor12345 February 8th 2023, 11:51 am

Good afternoon!

A clarifying question - should the image completely change to another when hovering or to the image just added effects?

If just adding an effect - use the hover pseudo-class and add the effects you need

For example (I used the forum widget to demonstrate):

Code:
<style>
.img_exp {
width: 190px;
height: 260px;
margin: 20px;
}

.img_exp:hover{
opacity: 0.6;
border: 2px solid red;
}

</style> <img src="https://starwars-visualguide.com/assets/img/characters/1.jpg" class="img_exp" />

Result (before and after hover):

How can I add another image, when hovering this image? Screen19

How can I add another image, when hovering this image? Screen18

You can also use the mix-blend-mode property only when hovering - https://codepen.io/Ilya-Babelnik/pen/poLGbXG
Or use filter - https://codepen.io/Ilya-Babelnik/pen/MWVZjJa

If you need something else, describe it in more detail. Maybe you have examples.


Last edited by Razor12345 on February 8th 2023, 12:07 pm; edited 2 times in total
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1586
Reputation : 268
Language : Ukr, Rus, Eng
Location : Ukraine

Back to top Go down

Solved Re: How can I add another image, when hovering this image?

Post by Razor12345 February 8th 2023, 11:55 am

[delete]
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1586
Reputation : 268
Language : Ukr, Rus, Eng
Location : Ukraine

Back to top Go down

Solved Re: How can I add another image, when hovering this image?

Post by skouliki February 8th 2023, 12:01 pm

skouliki
skouliki
Manager
Manager

Female Posts : 15397
Reputation : 1709
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

Solved Re: How can I add another image, when hovering this image?

Post by Friendly Toucan February 8th 2023, 12:21 pm

Hey,

Razor12345 wrote:A clarifying question - should the image completely change to another when hovering or to the image just added effects?

Completely to another.

I want to use this code:

Code:
<a target="_blank" href="https://help.forumotion.com/"><img style="width: 33px; height: 31px;" alt="" border="0" src="https://i.servimg.com/u/f21/16/89/96/68/faq11.png" /></a>
(I will change the URL:s later.)

I will put this code in a forum category description.

Right now, if you hover this image, it does nothing. What I want is for the image to turn into another custom image (the same size) when hovering, let's say this one:

https://i.servimg.com/u/f21/16/89/96/68/tipsnt12.png

I also re-size the image through this code by half, to give it a sharper look. The new "hover image" would also need to be re-sized to 33×31.

If someone could rewrite the code for me, that would be cool.

Cool

Thanks.
Friendly Toucan
Friendly Toucan
Forumember

Posts : 243
Reputation : 4
Language : English

https://cerulean-blues.forumotion.com

Back to top Go down

Solved Re: How can I add another image, when hovering this image?

Post by Razor12345 February 8th 2023, 12:52 pm

If each category has different pictures, then:

Insert the code in the forum description:

Code:
<a target="_blank" href="https://help.forumotion.com/"><img style="width: 33px; height: 31px;" alt="" border="0" src="https://i.servimg.com/u/f21/16/89/96/68/faq11.png" /></a>   

<script>
let imgForum = $('img[src="https://i.servimg.com/u/f21/16/89/96/68/faq11.png"]');
imgForum.hover(handlerIn, handlerOut);

function handlerIn () {
imgForum.attr('src', 'https://i.servimg.com/u/f37/11/71/42/99/raznoe10.png');
}

function handlerOut () {
imgForum.attr('src', 'https://i.servimg.com/u/f21/16/89/96/68/faq11.png');
}

</script>

This uses a link to the default image
Code:
let imgForum = $('img[src="https://i.servimg.com/u/f21/16/89/96/68/faq11.png"]');

This function is triggered when the user points at the image. Accordingly, a link to another image
Code:
function handlerIn () {
imgForum.attr('src', 'https://i.servimg.com/u/f37/11/71/42/99/raznoe10.png');
}

This function is triggered when the user removes the mouse from the image - the default image link.
Code:
function handlerOut () {
imgForum.attr('src', 'https://i.servimg.com/u/f21/16/89/96/68/faq11.png');
}

You can see the result on my test forum: https://testtesttest.forumotion.me/ (section Forum1)

If you will use the same images for categories, you have to assign different classes for the same images:

img class="first_forum"

Code:
<a target="_blank" href="https://help.forumotion.com/"><img class="first_forum" style="width: 33px; height: 31px;" alt="" border="0" src="https://i.servimg.com/u/f21/16/89/96/68/faq11.png" /></a>   

<script>
let imgForum = $('img.first_forum]');
imgForum.hover(handlerIn, handlerOut);

function handlerIn () {
imgForum.attr('src', 'https://i.servimg.com/u/f37/11/71/42/99/raznoe10.png');
}

function handlerOut () {
imgForum.attr('src', 'https://i.servimg.com/u/f21/16/89/96/68/faq11.png');
}

</script>
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1586
Reputation : 268
Language : Ukr, Rus, Eng
Location : Ukraine

sivastar and Friendly Toucan like this post

Back to top Go down

Solved Re: How can I add another image, when hovering this image?

Post by Friendly Toucan February 8th 2023, 2:31 pm

It works perfectly, thank you very much! thumleft

Topic marked as "solved".
Friendly Toucan
Friendly Toucan
Forumember

Posts : 243
Reputation : 4
Language : English

https://cerulean-blues.forumotion.com

Back to top Go down

Solved Re: How can I add another image, when hovering this image?

Post by skouliki February 8th 2023, 4:59 pm

Problem solved & topic archived.
Please read our forum rules: ESF General Rules
skouliki
skouliki
Manager
Manager

Female Posts : 15397
Reputation : 1709
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum