How can I change a jQuery UI widget's options after it has been created?

孤街醉人 提交于 2020-01-14 07:28:07

问题


It seems that the usual method of making jQuery widgets is to call a function on an element, passing the options as a parameter, and then not touching the widget directly again. Is there a way to change a widget's options after it has been created?

I want to create a draggable box that is aligned to a grid, but if the user resizes the page, I want to scale the grid. In the window resize event, how can I access the grid property of the draggable element?

$('.box').draggable({grid: [40,40]});
...
$(window).resize(function(){ ??? });

回答1:


From the Jquery ui documentation:

$( ".selector" ).draggable( "option", "grid", [50, 20] );

So you can do

$( ".box" ).draggable( "option", "grid", [width, height] );


来源:https://stackoverflow.com/questions/7997561/how-can-i-change-a-jquery-ui-widgets-options-after-it-has-been-created

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