JQuery UI draggable () and resizable ()

I want to write draggable () and resizable () code so that all future elements with a particular class inherit these plugins without calling them again.

$('div.resizeMe').resizable({
containment: 'parent',
minWidth: 400,
minHeight: 200
})

When the above code is executed, all divs with the resizeMe class inherit the resizable () function. But if I added BODY with a new div with the same class, I needed to execute this code again. Therefore, my goal is to rewrite this code so that it works for everyone, including future elements.

+3
source share
1 answer

You can use the .livequery()plugin here, it will execute in current matches and execute new elements as they appear, for example

$('div.resizeMe').livequery(function() {
  $(this).resizable({
    containment: 'parent',
    minWidth: 400,
    minHeight: 200
  });
});

div.resizeMe .

$.ajax() , ajax success complete, :

$.ajax({
  //options...
  success: function(data) {
    $('div.resizeMe', data).resizable({...options...});
  }
});

div.resizeMe , , .

+4

Source: https://habr.com/ru/post/1740861/


All Articles