创建jQuery UI窗口小部件后,如何更改其选项? [英] How can I change a jQuery UI widget's options after it has been created?

查看:84
本文介绍了创建jQuery UI窗口小部件后,如何更改其选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎制作jQuery小部件的通常方法是调用元素上的函数,将选项作为参数传递,然后不再直接接触小部件.创建小部件后,是否可以更改其选项?

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?

我想创建一个与网格对齐的可拖动框,但是如果用户调整页面大小,我想缩放网格.在窗口调整大小事件中,如何访问可拖动元素的grid属性?

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(){ ??? });

推荐答案

来自Jquery ui文档:

From the Jquery ui documentation:

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

所以你可以做

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

这篇关于创建jQuery UI窗口小部件后,如何更改其选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆