473,698 Members | 2,869 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Eventhandling and positioning of objects

Hallo,

for hours i'm searching for an solution for the following problem:
Inside a container i have some cathegories and in each of them some
questions (look at HTML),
The questions should be shown or hidden when clicking a cathegory (look
JS and CSS).
With a click on a question, it should be cloned and the clone should be
placed over the question so you can drag and drop it from there to
somewhere else.
The problem:
The clone is positioned in the upper left corner of "container" instead
of "question".
It looks like i get wrong values for offsetX (and -Y and layerX (and
-Y) in the function klonen()
(those for "container" instead of i.g. "cat1ques1" .
Can someone tell me what's going wrong?

Many thanks and best regards

Michael
----------- HTML -----------------

<div id="container" class="kontaine r">
<div id="vorlagen" class="vorlagen ">
<div class="cathegor y">
<div id="cat1" onclick="klappK at(this.id)">Ka tegorie1</div>
<div id="kat1frag1" class="frage">
cat1ques1
</div>
<div id="cat1ques2" class="frage">
cat1ques2
</div>
</div>
<div class="cathegor y">
<div id="cat2" onclick="klappK at(this.id)">Ka tegorie2</div>
<div id="cat2ques1" class="frage">
kat2frag1
</div>
<div id="cat2ques2" class="frage">
kat2frag2
</div>
</div>
</div>
</div>

----------- JAVASCRIPT -----------------

// cathegory navigation (show and hide questions)
function klappKat (where) {
if(!opend) { // var opend is globally, in the beginning it's false
klappe(where, "open");
}
else {
if (opend == where) {
klappe(where, "close");
opend = false;
return true;
}
else if (opend != where) {
klappe(opend, "close");
klappe(where, "open");
}
}
opend = where;
}

function klappe(where, how) {
var anzeige = "block";
if (how == "close") anzeige = "none";
var el = document.getEle mentById(where) ;
el = el.nextSibling;
while (el != null) {
if (el.nodeType == 1) {
el.style.displa y = anzeige;
if (el.attachEvent ) el.attachEvent( "onmousedow n", klonen);
if (el.addEventLis tener) el.addEventList ener("mousedown ", klonen,
false);
}
el = el.nextSibling;
}
}

function klonen(e) {
// event target
var was;
if(ie) was = event.srcElemen t.id;
if(!ie) was = e.target.id;

// if there's already a clone, prevent multiple cloning
if (was.indexOf("k lon") != -1) {
bewegflag = true;
}

// if there's no clone
else {
// cloning
var el = document.getEle mentById(was);
var klon = el.cloneNode(tr ue);
var klasse = document.create Attribute("clas s");
klasse.nodeValu e = "frageklon" ;
klon.setAttribu teNode(klasse);
var klonID = document.create Attribute("id") ;
klonID.nodeValu e = was + "klon";
klon.setAttribu teNode(klonID);
IDklon = was + "klon"; // IDklon global

// positioning - get position
if(!e) var e = window.event;
var ev = e;
if (ie) ev.cancelBubble = true;
if (ev.stopPropaga tion) ev.stopPropagat ion();

posarr[0] = el.offsetWidth; // posarr ist global
posarr[1] = el.offsetHeight ;
posarr[2] = ev.clientX;
posarr[3] = ev.clientY;
if (ie) {
posarr[4] = ev.offsetX; // maybe here is the problem?
posarr[5] = ev.offsetY; // and here
}
else if (!ie) {
posarr[4] = ev.layerX; // or here
posarr[5] = ev.layerY; // or here
}
var lin = (posarr[2] - posarr[4]);
var obn = (posarr[3] - posarr[5]);

var pos = posarr[0]+" | "+posarr[1]+" | "+ posarr[2]+" | "+
posarr[3]+" | "+ posarr[4]+" | "+ posarr[5] + " |lin: " + lin + " |obn:
" + obn;
window.status = pos;

// set position
klon.setAttribu te("style", "");
var ks = klon.style;
ks.left = parseInt(lin) + "px";
ks.top = parseInt(obn) + "px";
ks.width = parseInt(posarr[0]-15) + "px";

// append clone to document
el.appendChild( klon);
}
}

------------- CSS --------------
..kontainer {
width: 600px;
}

..kontainer .vorlagen {
font: 1em/1.3 Verdana, Arial, Helvetica, sans-serif;
background: #d9d9d9;
width: 500px;
border: 2px outset #708090;
padding: 15px;
overflow: auto;
}

..kontainer .vorlagen .kategorie {
letter-spacing: 0.8em;
font-weight: bold;
color: #FFFAFA;
background: #ccc;
border: 3px inset #708090;
padding: 10px 10px 10px 10px;
display: block;
}

..kontainer .vorlagen .kategorie .frage {
font: 0.8em/1.2 Verdana, Arial, Helvetica, sans-serif;
background: #FFFFF0;
color: #000;
border: 2px outset #708090;
padding: 5px 5px 5px 5px;
display: none;
}

..kontainer .vorlagen .kategorie .frageklon {
font: 0.6em/1.2 Verdana, Arial, Helvetica, sans-serif;
background: #9FA0FF;
color: #000;
border: 2px outset #708090;
padding: 5px 5px 5px 5px;
display: inline;
position: absolute;
top: 0;
left: 0;
z-index:100;
cursor: move;
}

Jun 12 '06 #1
2 1477
Michi wrote:
The clone is positioned in the upper left corner of "container"
instead of "question".
It looks like i get wrong values for offsetX (and -Y and layerX (and
-Y) in the function klonen()


You should be using offsetTop and offsetLeft, and walking up the element
chain to add each up. Read up about these properties online and how they are
values relative to the offsetParent element.

The logic to find the position of an arbitrary object on a page can be found
here:
http://www.javascripttoolbox.com/lib/objectposition/

This lib is much more accurate than others which simply sum up the offset*
values to find position and could surely be plugged into your code to easily
get accurate positioning results.

Good luck!

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jun 12 '06 #2
For drag and drop, try using the YAHOO UI library:

http://developer.yahoo.com/yui/

Well documented, reasonably easy to use, good browser compatibility.

ExG
Jun 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2711
by: Jane Withnolastname | last post by:
I am trying to re-work an old site by replacing the html with css. On the main page, I have a logo image which I needed centred on the initial screen. I found the solution here: http://www.wpdfd.com/editorial/wpd0103.htm#toptip (the second example) The problem is, under the image is a large table. But using the above positioning, now the table starts at the top of the page and runs underneath the image.
11
2632
by: NS | last post by:
I am relativly new to css positioning and have a question regarding the display of a DHTML pop-up Here is the basic HTML I am using: <html> <head> <script language="JavaScript"> <!--
4
2411
by: Marc Tanner | last post by:
Hello, I am currently working on a eventhandling system or something similar, and have the problem of loosing scope. I have read many interesting posts on this group and the faq article about closure, but it seems that i have still not understood everything. Below is my attempt to preserve the scope but it's not really nice and i think with the use of closure could it be done better. But at the moment i am quite confused and hope that...
3
1443
by: Bill Zack | last post by:
I have an interesting little ASP.NET problem. I have to position and show multiple "frames" in an IE6 browser at run time in a singe ASP.NET page. Each "frame" will contain a couple of navigation links and one chart object (currently an ActiveX control but we will be switching to native .NET controls soon). The number of frames shown on the page will be selected by the user dynamically at run time. What I need to do is define a...
3
1184
by: Claes Rådström | last post by:
Hi ! We have a base class that derives from System.Web.UI.Page Alla our pages derives from it. In our base class we want to have an access check, (own) , to verfy user access to the derived page. We want this in the base class so that the programmer cant forget to implement it. => we want a page load in the base class to fire first, if access is granted
2
1907
by: Jawiko | last post by:
I am trying to place objects like buttons, calendar, listboxes etc on a webform. I am strugling with the positioning. I placed all the objects in a cell and the cell centers itself on the page. However the objects don't appear on the webpage on the same place as the design form in Visual Web Developer. What can i do to keep the objects in place? any help would be appreciated.
6
2915
by: Mark | last post by:
hi, i'm trying to position something in the top right corner of a container, but i can't seem to figure out how to get it working. here's the html <div class='thumb'><a href='image.jpg'><img src='photos/thumbs/ bigsmile.jpg'></a><a class='del' href='?p=gallery&del=2'>x</a></div> where 'thumb' is my container, and 'del' should be aligned to the top right. here's the css
1
2219
by: final farewell | last post by:
Hello, I am using Ekhau Location Tracking System for an assignment. It is a system that is able to track configured tags attached to people or objects. I am new to the Ekahau Location Tracking System, but I have quite a good idea how it works. I have an assignment to develop a real application using the Ekahau Positioning Engine (The Engine is a software based real-time location system). The Location Tracking Model of the area to be...
1
1268
by: mohammadtaha | last post by:
Hi, I am using CSS to position objects (<SPAN> and <DIV> tags) on my webpage, which is working great on regular computer monitors, when I view the same page on a wide screen laptop monitor, one of my objects (<span id="logo">) changes position and is placed about 5 pixels below where it suppose to be. If I adjust the position to compensate for these five pixels, then the object is correctly positioned on the widescreen monitor but...
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
7723
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4366
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2328
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.