I want to be able to create window like boxes by clicking on an icon. If I’ve created one and click again, another shall be created and so on. With my code I can create several boxes, but the inner-div only gets created in the first opened window. The reason for this is that if several boxes are created, the divs will have id’s, which of course isn’t the right way to do it.
I actually have to questions here:
1. How can I change my code so I can create several boxes with inner-divs?
2. What is the best way to do if I want I want a box that gets created to overlap the last created one, but moved 10 px right and 10 px down?
Thanks!
The code:
PROGRAM.popup = function(width, height){
this.width = width;
this.height = height;
}
PROGRAM.popup.prototype.buildPopup = function(){
$('<div/>', {
id: 'window',
width: this.width,
height: this.height,
}).appendTo('#container');
$('<div/>', {
id: 'windowTop',
width: this.width,
}).appendTo('#window');
}
…
var popup = new PROGRAM.popup(300, 300);
popup.buildWindow();
var popup2 = new PROGRAM.popup(300, 300);
popup2.buildWindow();
You can remove the
windowID and use it as a class for styling. You can save the reference to the window div directly into variable and use it inappendTo().Retrieve previous window div and get his position using
offset(). Then set own offset based on those values.JavaScript:
HERE is the code.