How do I avoid a click event firing after dragging a gridster.js widget with clickable content?

前端 未结 5 1077
被撕碎了的回忆
被撕碎了的回忆 2021-01-21 15:32

I\'m using Gridster (http://gridster.net/) which able to drag the content inside the li . In my li there is a clickable div.

  • 5条回答
    •  猫巷女王i
      2021-01-21 16:12

      I fixed it with a trigger variable: var dragged = 0 Add the following to your gridster initialization which sets the variable to 1 on drag start:

      ...
          draggable: {
              start: function(event, ui) {
      
                  dragged = 1;
                  // DO SEOMETHING
              }
          }
      ....
      

      In your click event on the same object, check:

      ...
          if(!dragged){
              // DO SOMETHING
          }
          // RESET DRAGGED SINCE CLICK EVENT IS FIRED AFTER drag stop
      dragged = 0
      ....
      

    提交回复
    热议问题