views:

43

answers:

1

I am adapting the Coverflow technique to work with a div. The coverflow function (included as a js file in the head section) is here. When I dynamically add a DIV, it doesn't show up in the coverflow. I am wondering if there is a way to add a destroy function to this js file so that whenever a new div add is added, I can call the destroy method and then reinstantiate. Any suggestions on how I should go about doing this?

A: 

I wasted a lot of hours trying to come up with a good technique but finally this seems to work. If you're passing a div to the function like this:

$("div.divname").coverflow({});

Then, do this when you add a new DIV:

addDiv();
divBackup = $("div.divname")
$("div.divname").remove()
$("parentdiv").append(divBackup)
$("div.divname").coverflow({});

If anyone has a good suggestion, please feel free to add it. Until then, figured this would help someone facing the same problem.

Why this works?

When you remove and add the div, all the eventhandlers are destroyed as well. So, the next time you call the coverflow function, it reattaches to everything that is present. Beware though! If you attached other handlers, they will be lost as well. I know this is not the optimal solution but use it if you have no other option.

Legend