2

I'm practicing event handlers but I cant seem to figure out how to make similar mouseHover effect using javascript on the website of lol.garena.ph (home,news,guides etc. The nav buttons). Help me out please.

3
  • just the changing color when mouseHover but I don't know how to make it elevate just like on the lol.garena.ph Commented Jun 20, 2013 at 8:25
  • Combine css and javascript. Make an "hover" css class and add the class on mouse over with javascript. Commented Jun 20, 2013 at 8:26
  • yes that's exactly how I think it would work but my problem is what exactly do I put to the my javascript code to make it elevate, what sort of function. Commented Jun 20, 2013 at 8:29

2 Answers 2

3

Basically, you will have to make an .hover class :

.hover {
    position: relative;
    top: -5px; /* this will raise the element */
}

Then add the class to your element (with id el) with javascript :

<li onmouseover="this.className='hover';" onmouseout="this.className='';">Home</li>

Of course, this is just the principle. See a working example : http://jsfiddle.net/KbcPb/

But you could do it just with css : http://jsfiddle.net/42jLY/

Sign up to request clarification or add additional context in comments.

2 Comments

wow awesome! but how do I seperate the Nav buttons so that there will space between them? I tried doing <table width="120" border="0" cellspacing="10" cellpadding="10"> <tr> <th height="74" scope="col"><li onmouseover="this.className='hover';" onmouseout="this.className='';"></th> to seperate them but when I hover the Nav it elevates but puhes down the bottom part of the site.
margin-right: 5px;... You should learn a bit more CSS by your own :)
1

I'm using this for my task. It'll make it look like a CSS hover effect.

in the HTML code :

<h1 id="titleRegister" onmouseover="changeToBlueColor()" onmouseout="changeToBlackColor()"> Register </h1>

and for the function in javascript :

<script>
function changeToBlueColor(){
  document.getElementById("titleRegister").style.color = "blue";
}
function changeToBlackColor(){
  document.getElementById("titleRegister").style.color = "black";
}
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.