Skip to content
Related Articles

Related Articles

Improve Article Drag & Drop snap Option

  • Last Updated : 17 Mar, 2021

The snap option in the Drag and Drop module is used to make a draggable element snap to a grid or constrain its movement in the defined space. It is set to false by default. It can be defined with a single value or a function that will define the places where the element would snap.


Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

new Draggable ('element_id', {snap: size of the snap});


  • snap: It is used to make a draggable element constraint its movements.



  <script type="text/javascript" 
  <script type="text/javascript" 
    var elements = ['element'];
    window.onload = function () {
      elements.each(function (item) {
        new Draggable(item, {
          // Set the snap to a grid
          // of 500 pixels
          snap: 500 
        }) });
    <img id="element" src="gfg.png" />


My Personal Notes arrow_drop_up
Recommended Articles
Page :