Solved

OnMouseOver FLicker

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Html5 string 3 20
Increase the size of the modal in Bootstrap 5 22
CSS: Making responsive table look nicer 7 23
Best way to minify CSS with out breaking it 7 35
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

813 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

11 Experts available now in Live!

Get 1:1 Help Now