Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4fed4cf

Browse files
committed
Merge pull request gridstack#25 from ishields/grid-stack-animation
Add option for animating gridstack with css transitions
2 parents 490063b + 461123e commit 4fed4cf

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/gridstack.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,20 @@
101101
height: auto !important;
102102
}
103103
}
104+
105+
.grid-stack.grid-stack-animate .grid-stack-item {
106+
-webkit-transition: left .3s, top .3s, height .3s, width .3s;
107+
-moz-transition: left .3s, top .3s, height .3s, width .3s;
108+
-o-transition: left .3s, top .3s, height .3s, width .3s;
109+
-ms-transition: left .3s, top .3s, height .3s, width .3s;
110+
transition: left .3s, top .3s, height .3s, width .3s;
111+
}
112+
/*Don't animate the placeholder or when dragging/resizing*/
113+
.grid-stack.grid-stack-animate .grid-stack-item.ui-draggable-dragging,
114+
.grid-stack.grid-stack-animate .grid-stack-item.ui-resizable-resizing,
115+
.grid-stack.grid-stack-animate .grid-stack-item.grid-stack-placeholder{
116+
-webkit-transition: left .0s, top .0s, height .0s, width .0s;
117+
-moz-transition: left .0s, top .0s, height .0s, width .0s;
118+
-o-transition: left .0s, top .0s, height .0s, width .0s;
119+
transition: left .0s, top .0s, height .0s, width .0s;
120+
}

src/gridstack.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,12 @@
283283
auto: true,
284284
min_width: 768,
285285
float: false,
286-
_class: 'grid-stack-' + (Math.random() * 10000).toFixed(0)
286+
_class: 'grid-stack-' + (Math.random() * 10000).toFixed(0),
287+
animate: false
287288
});
288289

289290
this.container.addClass(this.opts._class);
291+
this.set_animation(this.opts.animate);
290292
this._styles = Utils.create_stylesheet();
291293
this._styles._max = 0;
292294

@@ -427,10 +429,12 @@
427429
self.grid.end_update();
428430

429431
self.grid._sort_nodes();
430-
_.each(self.grid.nodes, function (node) {
431-
node.el.detach();
432-
self.container.append(node.el);
433-
});
432+
setTimeout(function() { //if animating, delay detaching & reattaching all elements until animation finishes
433+
_.each(self.grid.nodes, function (node) {
434+
node.el.detach();
435+
self.container.append(node.el);
436+
});
437+
}, (self.opts.animate ? 300 : 0));
434438
};
435439

436440
el.draggable({
@@ -477,6 +481,15 @@
477481
}
478482
};
479483

484+
GridStack.prototype.set_animation = function (enable) {
485+
if (enable) {
486+
this.container.addClass('grid-stack-animate');
487+
}
488+
else {
489+
this.container.removeClass('grid-stack-animate');
490+
}
491+
}
492+
480493
GridStack.prototype.add_widget = function (el, x, y, width, height, auto_position) {
481494
el = $(el);
482495
if (typeof x != 'undefined') el.attr('data-gs-x', x);

0 commit comments

Comments
 (0)