tags:

views:

435

answers:

3

I am working on an ASP.NET web application that is required to bring up a popup on a roolover. I am using the "OnMouseOver" event and it works as expected. The problem is that the event is on a "hair trigger"; even a casual passage of the mouse over the control brings up the popup (which then must be manually dismissed). I want to add a delay so that a rapid pass over the control in question does not trigger the event. Is there a way to set such a delay or is there a different event that I could use to get the same "trigger event on a slow rollover"?

+3  A: 

One solution that comes to mind, there may be better ways though:

  1. Make the onmouseover call the function via a setTimeout delay
  2. Inside the function, check the mouse is actually over that element.

You could also use an onmouseout to clear the setTimeout, but then you'd have to store a reference to the timer in a global variable to get at it again.

Ant P.
A: 

I agree with Ant P... Its the best solution given the question.

Michael L
A: 

What I ended up doing is as follows (oRow is a table row but it could be any control):

function ItemMouseOver(oRow, "parameters for the popup") 
{
    oRow.showTimer = window.setTimeout(function() 
        { 
            alert('popup');
        }, 1000);
}
function ItemMouseOut(oRow)
{
    if (oRow.showTimer)
        window.clearTimeout(oRow.showTimer);

In the ASP.NET grid view RowDataBound event: I added the following code:

protected void ReportGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow && (
        e.Row.RowState == DataControlRowState.Normal 
        || e.Row.RowState == DataControlRowState.Alternate))
    {
        // get the input values for the popup for the row (stuff deleted)
        e.Row.Attributes["onmouseover"] = "javascript:ItemMouseOver(this,
            "parameters for the popup");";
        e.Row.Attributes["onmouseout"] = "javascript:ItemMouseOut(this);";
    } 
}

It works just fine. Thanks.

JonStonecash