Solved

OnMouseOver FLicker

Posted on 2008-10-01
3
366 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now