jquery resizable event does not end

狂风中的少年 提交于 2019-12-11 05:06:45

问题


i am making some interactive UI and using jquery for resize and mouse events.

I bind mouseOver and click event for all elements and when i get a click, i remove the click listener (so that it does not interefere with the resizable listeners).

this works fine till here, now the selected element can be resized. starting the resize works fine, but even after mouseup, the element resize event does not end, its still getting resized, with the mouse.

whats wrong ?

the thing is located here.

http://parth.me/builderjs/index.html

the main parts are :

var
  inspect = true,           // to disable inspect
  selected = null;          // currently selected event

function clickhandler(e) {
  console.log('click');
  if (selected != null)return;     // if some div is already selected, then return
  if (e.which == 3)return;         // if it was right click, return
  selected = $(e.target);          // selected = the element which received the click
  inspect = false;                 // disable inspection
  selected.addClass('selected');   // add SELECTED background + border
  $(window).unbind('click', clickhandler);  // remove the click listener
  $('.selected').resizable();               // make the selected element resizable
}

$(window).bind('click', clickhandler);    //bind the click event

'Esc' key is binded to unselect any selection.


回答1:


The contextMenu(which is listening to mouseclick event) is interefering with the resize end Event(which also wants the mouseclick event). Solution :

  $('.selected').resizable({
    start:function () {
      $("*").destroyContextMenu();
      console.log('resize started');
    },
    stop:function () {

      $("*").contextMenu({
          menu:'myMenu'
        },
        function (action, el, pos) {
          console.log(el);
          eval(action + '(el)');
        });
      console.log('resize stopped');
    },
    resize:function () {
      console.log("resize happened");
    }
  });

What i did was, destroy the context menu as soon as the resize started, so its not listening to the mouseclick event anymore. and make it back when the resize event ends.



来源:https://stackoverflow.com/questions/9541021/jquery-resizable-event-does-not-end

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!