gridstack.js icon indicating copy to clipboard operation
gridstack.js copied to clipboard

A little problem with style..

Open dani80vdt opened this issue 11 years ago • 7 comments

Hello I've a little problem with style.. I add dynamically style to item, but after drag or resize, it lose the style. I've tried to add again style after drop event, but it continue to doesn't work... were I did a mistake. Thanks for all Daniele

dani80vdt avatar Feb 19 '15 17:02 dani80vdt

What styles are you adding dynamically? Is there any reason why you wouldn't style it via a css file??

ascendantofrain avatar Feb 19 '15 17:02 ascendantofrain

at the moment shadow and background. I try to develop an application where user could change style of items (and move them). Maybe I could override "move_node" function?

dani80vdt avatar Feb 19 '15 17:02 dani80vdt

Ok I found a little solution.. store some styles in "on_end_moving" function (before removeAttr('style')) and restore them at the end of function

dani80vdt avatar Feb 19 '15 17:02 dani80vdt

Can you explain or give an example of what you're going to implement.

troolee avatar Feb 27 '15 05:02 troolee

Yes of course:

var o = $(this); node.el = o; self.placeholder.hide();

//Store styles  
var initialShadow = $(o).css("box-shadow");
var initialMoxShadow = $(o).css("-moz-box-shadow");
var initialWebKitShadow = $(o).css("-webkit-box-shadow");   
var initialBackground = $(o).css("background"); 
var initialTextAlign = $(o).css("text-align"); 
//ecc...


        o
            .attr('data-gs-x', node.x)
            .attr('data-gs-y', node.y)
            .attr('data-gs-width', node.width)
            .attr('data-gs-height', node.height)
            .removeAttr('style');

        self._update_container_height();
        self.container.trigger('change', [self.grid.get_dirty_nodes()]);

        self.grid.end_update();

           //Assign again styles
    $(o).css("box-shadow",initialShadow);
    $(o).css("-moz-box-shadow",initialMoxShadow);
    $(o).css("-webkit-box-shadow",initialWebKitShadow);
    $(o).css("background", initialBackground); 
    $(o).css("text-align", initialTextAlign); 
            //Ecc.........

dani80vdt avatar Mar 03 '15 16:03 dani80vdt

You could use the '.ui-draggable-dragging' and '.ui-resizable-resizing' selectors to negate any styles on the placeholders when you drag or resize??

ascendantofrain avatar Mar 03 '15 16:03 ascendantofrain

It is better to use CSS to customize how draggable item should look like. Please check this out

troolee avatar Mar 04 '15 07:03 troolee