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

Thread: Need to get the left position of a range input element

  1. #1
    Join Date
    Nov 2009
    Posts
    22

    Need to get the left position of a range input element

    I have a range input element on my page the controls a youtube movie's position and I need to figure out its left position so that I can move the movie. I will need to reset it if the user scrolls the page or resizes the window. I thought I could just use document.getElementById("progress-bar").style.left, but that yields nothing.

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    4,798
    Please post your codes you are using to help people understand your query.

    What do you mean by left? The "Range" input has attributes that describe where to start and end and the increments inbetween, so its position will always have a value relative to the position of the slider.

    When you post your code, please use forum BBCode taqs (see my signature for a hint)
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  3. #3
    Join Date
    Aug 2017
    Location
    Bulgaria
    Posts
    16
    This should work:
    Code:
    var leftPosition = document.getElementById("progress-bar").offsetLeft;

  4. #4
    Join Date
    Nov 2009
    Posts
    22
    that works. glad it was that easy. thanks nikolaydev!

  5. #5
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    4,798
    Hmmm, offsetLeft in the code I have been playing with reports an 8px difference even when the element is at 0px from the left.

    So are you sure its really giving you accurate results.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  6. #6
    Join Date
    Nov 2009
    Posts
    22
    i don't know if it's pixel perfect yet, but it looks to be close. I'll have to check later.

  7. #7
    Join Date
    Nov 2009
    Posts
    22
    Yes it seems to be perfect. Tried setting an image to a particular left setting via styles and it reported back the correct pixels each time.

Thread Information

Users Browsing this Thread

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

  1. JMRKER

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