dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: onmousewheel in Chrome

  1. #1
    Join Date
    Nov 2010
    Posts
    5

    onmousewheel in Chrome

    Hello world!

    I have an input type=text with value={date}
    User scrolls his mouse wheel on it.
    I need to see what is character number in the text field (in Firefox it's evt.rangeOffset) .
    How to get that in Chrome?


    Below is the code.


    <script>



    attach = function(){

    dateField= document.getElementById('a');
    dateField.onmousewheel=handleEvent;
    }


    handleEvent = function(evt){

    //???????????????????????
    //how to get character number on text field?
    }


    </script>

    <body onload="attach()">

    <input type=text value="01-10-2010" name=a id=a >

    </body>


    Thanks in advance.

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    What are you attempting to do?
    The code snippet given would not even work in Firefox; the mousewheel event does not work on <input> and Fx3+ uses a different event "DOMMouseScroll"

  3. #3
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    I don't get it. What's the use to scroll the mouse wheel over a text field? I used to think that createRange and rangeOffset are in connection with a selection made with a mouse, not with a scroll of the mouse wheel... What in fact you want to do, after all?

  4. #4
    Join Date
    Nov 2010
    Posts
    5
    I want to change date in the text field.
    When the user scrolls on date, the date is changed.
    When the user scrolls on month, the month is changed.
    When the user scrolls on year, the year is changed.

  5. #5
    Join Date
    Nov 2010
    Posts
    5
    I managed to add mousewheel event in Chrome.
    But I can't figure out what character number of text field is under the mouse.

    Below is the code for that for IE and firefox:

    UIUtils._getCursorOffsetFromEvent = function(evt) {

    if (evt.type != "keydown") {

    //for FireFox:
    if ( evt.rangeOffset > -1 ) {
    return evt.rangeOffset;
    }


    //For IE:
    var textRange = evt.srcElement.createTextRange();


    var offsetX = (evt.offsetX > 0) ? evt.offsetX : 0;
    while ( textRange.boundingWidth > offsetX ) {
    textRange.moveEnd( "character", -1 );
    }
    return textRange.text.length;
    }
    return UIUtils._getSelectionEnd( (evt.target) ? evt.target : evt.srcElement );
    }

    How do I do that in Chrome?

  6. #6
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Do you understand what the mouse wheel is? Do you know what a user must do to start the onmousewheel event? I guess you confound the terms.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles