Last active
          May 21, 2018 08:37 
        
      - 
      
- 
        Save caleb531/5886072 to your computer and use it in GitHub Desktop. 
    Makes a jCanvas layer draggable along a defined grid
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // Available in jCanvas v20.1.0 | |
| // The pixel multiple to snap to | |
| var snapToAmount = 40; | |
| // Round the given value to the nearest multiple of n | |
| function nearest(value, n) { | |
| return Math.round(value / n) * n; | |
| } | |
| $('canvas').drawArc({ | |
| layer: true, | |
| draggable: true, | |
| fillStyle: '#36c', | |
| x: 160, y: 120, | |
| radius: 50, | |
| updateDragX: function (layer, x) { | |
| return nearest(x, snapToAmount); | |
| }, | |
| updateDragY: function (layer, y) { | |
| return nearest(y, snapToAmount); | |
| } | |
| }) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
So easy to integrate thank you!