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 7190671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:33:56+00:00 2026-05-28T19:33:56+00:00

Im struggling to create a functionality which keeps on incrementing css property of an

  • 0

Im struggling to create a functionality which keeps on incrementing css property of an element when someone presses and ‘holds’ a button.

something like this:

var timeoutId = 0;

$('#left').mousedown(function() {
    timeoutId = setTimeout(myFunction, 1000);
}).bind('mouseup mouseleave', function() {
    clearTimeout(timeoutId);
});

function myFunction() {
 var left = parseInt($("#menuElem").css('left')) + 10;
 $("#menuElem").animate({
    'left' : left + 'px'
 });

}

I want that myFunction to be repeated again and again until mouseup or mouseleave event is fired.

cheers

  • 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-05-28T19:33:57+00:00Added an answer on May 28, 2026 at 7:33 pm

    According to this SO question you can’t detect the current up or down state of a key, only monitor the respective events.

    So you’d need something like this i guess

    var mouseIsDown = false;
    
    $('#button').mousedown(function(){
        mouseIsDown = true;
        incrementValue;
    });
    
    $('#button').mouseup(function(){
        mouseIsDown = false;
    });
    

    Then have that function be all like:

    function incrementValue() {
        whatever++;
        if(mouseIsDown){
            setTimeout("incrementValue()", 20);
        }
    }
    

    On mouse down, the mouseIsDown var gets set to true, and it starts a loop that continues to increment (at whatever interval you set the time parameter to in setTimeout()) until mouseIsDown is false, which happens on mouseup.

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

Sidebar

Related Questions

I am struggling to find a way to create the Forms functionality that I
I have been struggling to create a django form which users can fill and
Hey guys I am struggling to create a query which gives schedule of a
I have been struggling to create a Dropdown list which will display Country names
I'm almost embarassed, but I'm struggling to create a regular expression to change something
I am trying to create an Android View, but im struggling. So hoping someone
I'm struggling to create a table view controller that has anything more than just
I'm struggling to create a custom UITableViewCell (in IB) that has a UIImageView on
I've been struggling with a feature I've been trying to create for sometime. The
I'm using mysql to create an hotel booking system, but i am struggling a

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.