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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:06:16+00:00 2026-06-13T05:06:16+00:00

I have 4 arrows that each one moving the piece element now i want

  • 0

I have 4 arrows that each one moving the piece element
now i want to create a reset button that will return the piece to the default place

//piece object
var piece = {};
piece.el = $('#piece');
piece.moveDelta = function(dx, dy){
    var pos = this.el.position();
    this.el.css('left', pos.left+dx);
    this.el.css('top', pos.top+dy);
};
$(document).ready(function(){
    //init deltas
    $('#btn-up').data('dx', 0).data('dy', -100);
    $('#btn-left').data('dx', -100).data('dy', 0);
    $('#btn-right').data('dx', 100).data('dy', 0);
    $('#btn-down').data('dx', 0).data('dy', 100);
    //assign click event
    $('.btn-arrow').click(function(){
        piece.moveDelta($(this).data('dx'), $(this).data('dy'));
    });
});
  • 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-13T05:06:17+00:00Added an answer on June 13, 2026 at 5:06 am
       //piece object
    var piece = {};
    
    var defaultX = null;
    var defaultY = null;
    
    piece.el = $('#piece');
    piece.moveDelta = function(dx, dy){
        var pos = this.el.position();
        if(defaultX === null && defaultY === null ){
             defaultX = pos.left;
             defaultY = pos.top;
        }
        this.el.css('left', pos.left+dx);
        this.el.css('top', pos.top+dy);
    };
    piece.reset = function () {
       this.el.css('left', defaultX);
       this.el.css('top', defaultY);
    };
    $(document).ready(function(){
        //init deltas
        $('#btn-up').data('dx', 0).data('dy', -100);
        $('#btn-left').data('dx', -100).data('dy', 0);
        $('#btn-right').data('dx', 100).data('dy', 0);
        $('#btn-down').data('dx', 0).data('dy', 100);
    
    
        //assign click event
        $('.btn-arrow').click(function(){
            piece.moveDelta($(this).data('dx'), $(this).data('dy'));
        });
        $("#btn-reset").click(function(){
           piece.reset();
        });
    
    });
    

    you can use the reset method defined above. Fiddle

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

Sidebar

Related Questions

I have a group of links that I call fancybox on with the arrows
I have to create the classic combo-box with arrows up and down to increment
In one of my Activities I have a ListView that displays a list of
i have a layout that looks like this: (without the arrows) the pictures of
I have an Excel2010 VBA userform that has one comboBox, from which the user
I have a set of divs that represent story categories. In each category, there's
How would one implement KeyListener so that I can create a two-player system where
I have a set of inputs and for each value that I'm inputting I
I have a Script in my HTML document that detects when one of the
I have a div that loads in the number of images on each page.

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.