Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
Getting the left and top positions with a draggable control

I have few components on my page which are draggable. They have the class draggable. When this is dragged and stops I need to get the left and top positions

        function init() {
            var p = $('#groups-parent');
            $('.draggable').draggable({
                obstacle: ".obstacle",
                preventCollision: true,
                containment: [
                    p.offset().left, p.offset().top, p.offset().left + p.width() - 225, p.offset().top + p.height() - 50
                ], 
                start: function(event, ui) {
                    $(this).removeClass('obstacle');
                },
                stop: function (event, ui) {
                    console.log(ui);
                    $('#groups-parent').css({ 'min-height': Math.max(500, ui.position.top + 50) });
                    $(this).addClass('obstacle');
                    
                    getTopLeftPosition();
                }
            });  
        }

Here is my function that should get the left and top positions.

        function getTopLeftPosition(e) {
            var coordX = e.pageX - $(this).offset().left,
                coordY = e.pageY - $(this).offset().top;

            alert(coordX + ' , ' + coordY);
        }

This does not work. All I get in my browser is this error message

Cannot read properties of undefined (reading 'left')

How can I get this left and top positions? The alert should indicate it.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You probably just need to bind this to the function, by changing

getTopLeftPosition();

to either

getTopLeftPosition.call(this, event);

or

getTopLeftPosition.bind(this)(event)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!