Solved

OnMouseOver FLicker

Posted on 2008-10-01
3
374 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
[X]
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
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

724 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