1

I have a web page with a navigation bar at the top that I want to appear to change colors when you mouse over it by changing to a different file that is that image in a different color. I want to make a function that will create the HTML code for this bar. I started on it but I am confused as where to go from here.

<html>
<head>
    <script LANGUAGE="JavaScript">
        function NavigationBar() {

            var reg1 = new Image
            var red1 = new Image

            reg1.src = "1.gif"
            red1.src = "1R.gif"

            onMouseOver = "document.thereg1.src=red1.src"
            onMouseOut = "document.thereg1.src=reg1.src"
        }
    </script>
</head>

<body>
    <a href="Home Page.html" NavigationBar(thereg1)>
        <img src="1.gif" Name="thereg1">
    </a>
</body>
</html>
1
  • 4
    do you mean the bar colour or the link background colour? Regardless, both can be done with CSS, javascript is probably overkill Commented Nov 5, 2013 at 18:20

1 Answer 1

1

You don't even have to use Javascript for that

Just stick with CSS because it really easier and do like this :

link {

background-image: url ...
}

link:hover{
background-image: ..
transition : background-image 0.5s ease-in-out;
}

this will just change the image on hover

IF you want to have a nice transition use transition

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

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.