Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8510239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:38:52+00:00 2026-06-11T03:38:52+00:00

I would like to trigger some functions according to a position of an element.

  • 0

I would like to trigger some functions according to a position of an element. This element’s position changes every tenth second. There is two dozens functions to trigger.

I thought about this pseudo-code :

When element position changes{
  Loop through all the coordinates to see if a function can be triggered{
     if the current element position matches the function's triggering position 
         execute the function
     }
}

But looping through all possible position each split seconds burdens the browser. So if there is a way to have events to do that.

Is it possible ?

Edit:
After Beetroot-Beetroot comment, I must say that the element that moves only moves on an X abscissa : so just one dimension.

It’s much like a horizontal timeline moving from left to right, where some animation happen when a certain year is reached.
However the moving speed can be increased by the user, so fixed time to trigger animation is not an option.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:38:53+00:00Added an answer on June 11, 2026 at 3:38 am

    There must be many ways to achieve what you want. The code below exploits jQuery’s capability to handle custom events to provide a “loosely-coupled” observer pattern.

    $(function() {
    
        //Establish the two dozen functions that will be called.
        var functionList = [
            function() {...},
            function() {...},
            function() {...},
            ...
        ];
    
        var gridParams = {offset:10, pitch:65};//Example grid parameters. Adjust as necessary.
    
        //Establish a custom event and its handler.
        var $myElement = $("#myID").data('lastIndex', -1).on('hasMoved', function() {
            $element = $(this);
            var pos = $element.position();//Position of the moved element relative to its offset parent.
            var index = Math.floor((pos.left - gridParams.offset) / gridParams.pitch);//Example algorithm for converting pos.left to grid index.
            if(index !== $element.data('lastIndex')) {//Has latest movement align the element with the next grid cell?
                functionList[index](index, $element);//Call the selected function.
                $element.data('lastIndex', index);//Remember index so it can be tested mext time.
            }
        });
    });
    
    $(function() {
        //(Existing) function that moves the element must trigger the custom 'hasMoved' event after the postition has been changed.
        function moveElement() {
            ...
            ...
            ...
            myElement.trigger('hasMoved');//loosely coupled 'hasMoved' functionality.
        }
    
        var movementInterval = setInterval(moveElement, 100);
    });
    

    As you can see, an advantage of loose-coupling is that a function and the code that calls it can be in different scopes – .on('hasMoved', function() {...} and myElement.trigger('hasMoved') are in different $(function(){...}) structures.

    If you wanted to add other functions to change the position of myElement (eg first, previous, next, last functions), then, after moving the element, they would each simply need to trigger ‘hasMoved’ to ensure that the appropriate one of your two dozen functions is called, without needing to worry about scopes.

    The only thing you need to ensure is that your two dozen functions are scoped such that they can be called by the custom event handler (ie that they are in the same scope or an outer scope, up to and including the global scope).

    I’ve had to make many assumptions, so the code above will not be 100% correct but hopefully it will provide you with a way ahead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like links to be trigger on double click. Something simple like this:
I have this piece of logic I would like to implement as a trigger,
I would like to trigger the js function onClick from button. for some reason
I would like to launch fancybox from another function. I need this trigger after
I would like to trigger some jQuery autocomplete events from outside of autocomplete but
I would like to trigger an event when my VideoView is done playing? How
I have a video view that is full screen and would like to trigger
I would like to have a Maven goal trigger the execution of a java
I would like to fire an UPDATE trigger only if a certain fields has
Using the Northwind sample: I would like to create an insert trigger on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.