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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:14:37+00:00 2026-06-01T00:14:37+00:00

Hey I am implementing the drag and drop operations using Kineticjs Now I want

  • 0

Hey I am implementing the drag and drop operations using Kineticjs
Now I want the images to snap to each other if they get close ..
I saw the animals on beach example in KineticJs which was no help to me for my functionality
then saw the jquery snap to grid thing..But if I use that then I’ll have to get rid of KineticJs .Is thr any way to implement jquery snap propery to the elements in kineticJs
cause in jquery they have passed the id of the img to make it draggable and then snap.
So how can I use this with my kinetic.js images

jquery draggable: http://jqueryui.com/demos/draggable/#snap-to

kinetic.js: http://www.kineticjs.com/

Thanks

Ashish

  • 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-01T00:14:39+00:00Added an answer on June 1, 2026 at 12:14 am

    If you’re going for something that snaps to an nxm grid you’d want to add a listener that calls a function which snaps it. You’d probably want to do this at “dragend”

    http://www.html5canvastutorials.com/kineticjs/html5-canvas-drag-and-drop-events-tutorial/

      box.on("dragend", function(){
        snaptogrid(box);
      });
    

    … 100×100 grid for square tiles

      function snaptogrid(YourObject){
         YourObject.x = Math.floor(YourObject.x/100) * 100 + 50;
         YourObject.y = Math.floor(YourObject.y/100) * 100 + 50;
      }
    

    ex: if YourObject.x = 325, then you’ll have Math.floor(3.25)*100+50 = 350. The left and top should both be at 300, while, the center is at 350.

    Edit, oops missed part of the question. For snapping to other squares, here’s what I’d do:

    function snaptoOther(YourSquares, index){
       var lastone = YourSquares.length-1;
       var maxDist = 125;
       var minDist = 75;
       var squarelength = 100;
    
       for(var i=0; i<lastone; i++)
       {
         var checkx = abs(YourSquares[index].x - YourSquares[i].x);
         var checky = abs(YourSquares[index].y - YourSquares[i].y);
         var multiplyX = Math.round((YourSquares[index].x - YourSquares[i].x)/squarelength);
         var multiplyY = Math.round((YourSquares[index].y - YourSquares[i].y)/squarelength);
    
          if(checkx < maxDist && checkx > minDist && i !== index)
            {
              YourSquares[index].x = YourSquares[i].x + multiplyX*squarelength;
            }
          if(checky < maxDist && checky > minDist && i !== index)
            {
              YourSquares[index].y = YourSquares[i].y + multiplyY*squarelength;
            }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey, I'm using Levenshteins algorithm to get distance between source and target string. also
Hey right now I'm using jQuery and I have some global variables to hold
Hey, I'm currently looking for various methods of implementing collision response in 2D video
Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)
Hey so what I want to do is snag the content for the first
Hey, I've been developing an application in the windows console with Java, and want
Hey guys IM Looking at Implementing MVVM in Silverlight. Kind of new to Silverlight
Hey guys, I have an idea that I'd like to start implementing that at
Hey guys I was wondering if there is a way to get a certain
Hey, I want to know how to connect databases with C++? Any cross-platform solution

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.