/    Sign up×
Community /Pin to ProfileBookmark

A more softer way to enhance an item when the mouse fly over it

Hi,

I’m new with html and javascript language and I’m building a personal webpage for self development/hobbie/entertainment. I want to do the simple thing of make an item move or be someway highlighted when the mouse fly over it and to do it I made the following code:

[CODE]<script>
function hovermouse(x) {
x.style.height = “113px”;
x.style.width = “113px”;
}

function normalImg(x) {
x.style.height = “80px”;
x.style.width = “80px”;
}
</script>[/CODE]

Then, with the simple <img> tag and calling the above functions I can do the desire effect:

[CODE]<img onmousemove=”hovermouse(this)” onmouseout=”normalImg(this)” src=”images/snoopy.gif” alt=”HobbiesButton” width=”80″ height=”80″>[/CODE]

This method works but is kinda ugly. The items change their size in a very rough way and all the page shakes when the mouse fly over the item which makes this funcionality a little bit annoying.

Can someone tell me another way of doing this kind of effect in a more softer way where just the item itself moves (in a more softer way) when the mouse fly over it and not all the page?

Thanks in advance!

Regards

to post a comment
HTML

3 Comments(s)

Copy linkTweet thisAlerts:
@Kevin2Dec 18.2015 — CSS is a much better choice than JavaScript

.grow {
width: 80px;
height: 80px;
transition: all 1s ease-in-out;
}
.grow:hover {
width: 113px;
height: 113px;
}

[code=html]<img class="grow" src="images/snoopy.gif" alt="HobbiesButton">[/code]
You can play around with the timing and easing.
Copy linkTweet thisAlerts:
@SempervivumDec 18.2015 — where just the item itself moves[/QUOTE]Try this:
[code=html]<div class="wrapper"><img class="grow" src="images/snoopy.gif" alt="HobbiesButton"></div>[/code]
[code=html].grow {
width: 80px;
height: 80px;
transition: all 1s ease-in-out;
position: absolute;
top: 0px;
left: 0px;
}
.grow:hover {
width: 113px;
height: 113px;
}
.wrapper {
width: 80px:
height: 80px;
position: relative;
} [/code]

When you write this the image stays centered:
[code=html].grow:hover {
width: 113px;
height: 113px;
left: -16px;
top: -16px;
}[/code]
Try what you like more.
Copy linkTweet thisAlerts:
@Kevin2Dec 18.2015 — @Sempervivum: much nicer! ?
×

Success!

Help @Adam_Brave spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...