Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

OnMouseOver FLicker

Posted on 2008-10-01
3
371 Views
Last Modified: 2012-05-05
Hello, I dont do much client side scripting.  With the code below the background is changed onmouseover but it flickers back and forth between the two images when I move my mouse around the div.  how can i fix this?


        function itemMouseOver(DivID) {
            document.getElementById(DivID).style.background = 'url(../Images/Webmasters/MyLinks/ItemBg_OnMouseOver.jpg)';
        }
        function itemMouseOut(DivID) {
            document.getElementById(DivID).style.background = 'url(../Images/Webmasters/MyLinks/ItemBg_OnMouseOut.jpg)';
        }


<div class="MyLinksItemDiv" id="10" onmouseover="itemMouseOver(10);" onmouseout="itemMouseOut(10);">

Thanks!
0
Comment
Question by:grogo21
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
Badotz earned 500 total points
ID: 22626315
Try something like this:



//
function itemMouseOver(DivID) {
	var d = document.getElementById(DivID);
	if (d.style.background != 'url(../Images/Webmasters/MyLinks/ItemBg_OnMouseOver.jpg)') {
	{
		d.style.background = 'url(../Images/Webmasters/MyLinks/ItemBg_OnMouseOver.jpg)';
	}
}
//
function itemMouseOut(DivID) {
	var d = document.getElementById(DivID);
	if (d.style.background != 'url(../Images/Webmasters/MyLinks/ItemBg_OnMouseOut.jpg)') {
	{
		document.getElementById(DivID).style.background = 'url(../Images/Webmasters/MyLinks/ItemBg_OnMouseOut.jpg)';
	}
}

Open in new window

0
 
LVL 29

Expert Comment

by:Badotz
ID: 22626330
Sorry, typo in the second function:


//
function itemMouseOut(DivID) {
	var d = document.getElementById(DivID);
	if (d.style.background != 'url(../Images/Webmasters/MyLinks/ItemBg_OnMouseOut.jpg)') {
	{
		d.style.background = 'url(../Images/Webmasters/MyLinks/ItemBg_OnMouseOut.jpg)';
	}
}

Open in new window

0
 

Author Comment

by:grogo21
ID: 22631371
Hello, that did not fix it.  Thanks for tring though.  I ended up using :
        var LastDiv = 0
        function itemMouseOver(DivID) {
            if (LastDiv != DivID) {
                if (LastDiv != 0) {
                    document.getElementById(LastDiv).style.background = 'url(../Images/Webmasters/MyLinks/ItemBg_OnMouseOut.jpg)';
                }
                document.getElementById(DivID).style.background = 'url(../Images/Webmasters/MyLinks/ItemBg_OnMouseOver.jpg)';
                LastDiv = DivID
            }
        }
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question