4

I want to know if it is possible to add properties to the event object that gets passed to the bind() event handler function. I have a piece of code that this bound to "mousedown". I would like to trigger this event explicitly. The problem is that the bind() handler expects some event properties that are provided when the mouse trigger the event; namely 'pageX' and 'pageY'.

I know that I can pass additional parameters as an array into Trigger() but I would prefer to not change the the bind() code. This may not be possible.

I'd like to trigger the handler below and 'fake' the pageX. Can that be done somehow?

 currentObj.bind("mousedown", function(e) {
                var handleElement = currentObj.find(".HwSliderHandle");
                var offsetMultiplier = calculateOffsetMultiplier();
                var newPosition = Math.round(e.pageX/offsetMultiplier) - sliderInfo.contextOffset.left;
                moveHandleTo(handleElement, newPosition);                    
            });

2 Answers 2

3

You can create your own event object and then send it using the trigger() function :

var e = new jQuery.Event("mousedown");
e.pageX = 'fake value';
currentObj.trigger(e);
Sign up to request clarification or add additional context in comments.

Comments

0

Here's an approach:

    $(document).ready(DocReady);

    function DocReady()
    {
        $("#test").bind("mousedown", mouseDown);
    }
    function mouseDown(e)
    {
       alert("X: " + e.pageX + ", Y: " + e.pageY);      
    }

    function fakeIt()
    {
       var e = { pageX: 40, pageY: 50 };
       mouseDown(e);
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.