Search code examples
jquerypackery

the second parameter of packery fit method(jQuery)?


I am using the packery library.

The problem is about the second parameter of fit method. The document says it should be an element, but I have no idea of what 'element' means.

The following link is an example of my problem.

Link

When I click the resize button, fit seems not working. If it's working, when I resize 'post 1', 'post 2' should go to the second row rather than being overlapping.

The following link is an example of what I mean, but I wish to trigger by buttons instead.

Link


Solution

  • http://jsfiddle.net/9Q5sZ/3/ check this fiddle

    if (isLarge) {
            $("div#container").packery('fit', div[0]);
        } 
    

    to provide the target Element use div[0].

    The variable "div" is the Jquery output object ,which during runtime will be an Object Array

    div: jQuery.fn.init[1]
    0: div.post.large
    context: button.resize
    length: 1
    prevObject: jQuery.fn.init[1]
    __proto__: Object[0]
    

    as you can see additional parameters like context,proto,length etc.But your Packery plugin required only exact div object (this object is meant by element in the packery documents).hence div[0] will provide exact div object

    div[0]: div.post
    accessKey: ""
    align: ""
    attributes: NamedNodeMap
    baseURI: "http://fiddle.jshell.net/9Q5sZ/3/show/"
    childElementCount: 2
    childNodes: NodeList[5]
    children: HTMLCollection[2]
    classList: DOMTokenList[1]
    className: "post"
    clientHeight: 100
    clientLeft: 3
    clientTop: 3
    clientWidth: 211
    contentEditable: "inherit"
    dataset: DOMStringMap
    dir: ""
    draggable: false
    firstChild: text
    firstElementChild: button.resize
    hidden: false
    id: ""
    innerHTML: "↵        <button class="resize">resize</button>↵        <div>post 1</div>↵    "
    innerText: "resize↵post 1↵"
    isContentEditable: false
    lang: ""
    lastChild: text
    lastElementChild: div
    localName: "div"
    namespaceURI: "http://www.w3.org/1999/xhtml"
    nextElementSibling: div.post
    nextSibling: text
    nodeName: "DIV"
    nodeType: 1
    nodeValue: null
    offsetHeight: 106
    offsetLeft: 0
    offsetParent: div#container
    offsetTop: 0
    offsetWidth: 217
    onabort: null
    onbeforecopy: null
    onbeforecut: null
    onbeforepaste: null
    onblur: null
    oncancel: null
    oncanplay: null
    oncanplaythrough: null
    onchange: null
    onclick: null
    onclose: null
    oncontextmenu: null
    oncopy: null
    oncuechange: null
    oncut: null
    ondblclick: null
    ondrag: null
    ondragend: null
    ondragenter: null
    ondragleave: null
    ondragover: null
    ondragstart: null
    ondrop: null
    ondurationchange: null
    onemptied: null
    onended: null
    onerror: null
    onfocus: null
    oninput: null
    oninvalid: null
    
    //Object continues