I have a DIV with the attribute "Position: relative;". Now there are three of these divs. They all get a unique identifier, etc.
Now, if I press DIV, I want it to plunge into a certain position in the document. Although I can not determine the left / top values, because if I use the "top" and "left", it will relate the position on the left to the parents.
Maybe a little unclear, but here's what I got.
CSS clickable div that will move.
div#left_hldr .switch_project {
z-index: 1001;
position: relative;
margin: 10px 0px 0px 0px;
cursor: pointer;
}
Now, the jQuery code that I have right now.
$(".switch_project").live('click', function () {
var More_Id = $(this).attr("id");
var Id_Split = More_Id.split("_");
var Project_Id = Id_Split[2];
var Ori_Left = $(this).offset().left;
var Ori_Top = $(this).offset().top;
var New_Top = $("div#content_hldr").offset().top;
var New_Left = $("div#content_hldr").offset().left;
var Div_Rep = $(this);
$(Div_Rep).children(".more_info").fadeOut("fast");
$("div#content_hldr").fadeOut("fast");
$(Div_Rep).animate({
top: New_Top,
left: New_Left
}, "slow", function () {
$("div#content_hldr").load("content/content.projects.php?id=" + Project_Id, function () {
Cufon.replace('h2');
});
$("div#content_hldr").fadeIn("fast", function () {
$(Div_Rep).hide();
$(Div_Rep).css({
top: Ori_Top,
left: Ori_Left
});
$(Div_Rep).children(".more_info").show();
$(Div_Rep).fadeIn("medium");
});
});
});
source
share