如何使Gridster添加小部件可调整大小?

编程入门 行业动态 更新时间:2024-10-28 16:17:08
本文介绍了如何使Gridster添加小部件可调整大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的项目基于小提琴

但是我已经做到了所以你可以使用以下方式添加小部件:

But I have made it so you can add widgets using:

$(document).on("click", "#add", function() { var gridster = $(".layouts_grid ul").gridster().data('gridster'); gridster.add_widget('<li class="layout_block" data-row="1" data-col="1" data-sizex="1" data-sizey="1"><div class="remove_element">X</div></li>', 1, 1) .resizable({ grid: [grid_size + (grid_margin * 2), grid_size + (grid_margin * 2)], animate: false, minWidth: grid_size, minHeight: grid_size, containment: '#layouts_grid ul', autoHide: true, stop: function(event, ui) { var resized = $(this); setTimeout(function() { resizeBlock(resized); }, 300); } });

现在t他的作品,它确实创建了一个新的小部件,但小部件不可调整大小。虽然它是用所需的类和id创建的,但我认为这是因为它是一个动态添加的小部件。有什么方法可以让这个工作吗?

Now this works, it does create a new widget, but the widget is not resizeable. Even though it's created with the class and id needed, I think it's because It's a dynamically added widget. Is there any way I can get this to work?

谢谢。

推荐答案

我会尝试这样的事情:

$(document).on("click", "#add", function() { var gridster = $(".layouts_grid ul").gridster().data('gridster'); gridster.add_widget('<li class="layout_block" id="block" data-row="1" data-col="1" data-sizex="1" data-sizey="1"><div class="remove_element">X</div></li>', 1, 1); $('#block').resizable({ grid: [grid_size + (grid_margin * 2), grid_size + (grid_margin * 2)], animate: false, minWidth: grid_size, minHeight: grid_size, containment: '#layouts_grid ul', autoHide: true, stop: function(event, ui) { var resized = $(this); setTimeout(function() { resizeBlock(resized); }, 300); } });

更多推荐

如何使Gridster添加小部件可调整大小?

本文发布于:2023-11-11 13:36:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578592.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:部件   可调整   大小   Gridster

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!