germanysbestkeptsecret / Wookmark-jQuery

A jQuery plugin to create a dynamic, multi-column layout.
MIT License
2.63k stars 759 forks source link

Variable cannot be read for items grid #137

Closed sanbrons closed 10 years ago

sanbrons commented 10 years ago

function itemWidth() { $(".action").click(function() { var width = $(this).attr("data-width"); Grid(width); }); }

function Grid(width){ var handler = $('div.tiles div.item'); handler.wookmark({ align: "center", autoResize: true, // This will auto-update the layout when the browser window is resized. container: $('div.zee-container'), // Optional, used for some extra CSS styling offset: 10, // Optional, the distance between grid items outerOffset: 10, // Optional, the distance to the containers border itemWidth: width // Optional, the width of a grid item }); }

I am trying to send value from data-width on click on the button. But the function for Grid() does not seem to send the width variable into the itemWidth. The value does sent, but it does not enter itemWidth

Sebobo commented 10 years ago

Hi,

are you calling the grid function multiple times? If so you should reuse the handler variable and not reinitialize it on each call. Your current code will create a new wookmark instance on each call and won't remove the old one. Maybe that's the source of the problem.

Just move the "var handler = ..." outside of the function.

sanbrons commented 10 years ago

hi,

i did call grid function multiple time, first is when the page is load and button is click for this example. where should i move the var handler.

Sebobo commented 10 years ago

Try something like this:

var handler = $('div.tiles div.item');

function Grid(width){
  ...
}
praw commented 10 years ago

Gm.g Sent from my BlackBerry 10 smartphone. From: Sebastian HelzleSent: Wednesday, May 14, 2014 08:41To: GBKS/Wookmark-jQueryReply To: GBKS/Wookmark-jQuerySubject: Re: [Wookmark-jQuery] Variable cannot be read for items grid (#137)Closed #137.

—Reply to this email directly or view it on GitHub.

praw commented 10 years ago
                                                                                                                                                                                                                                                                      Sent from my BlackBerry 10 smartphone.                                                                                                                                                                                                                                        From: Sebastian Helzle8kk g‎Sent: Wednesday, May 14, 2014 08:41To: GBKS/Wookmark-jQueryReply To: GBKS/Wookmark-jQuerySubject: Re: [Wookmark-jQuery] Variable cannot be read for items grid (#137)Closed #137.

—Reply to this email directly or view it on GitHub.