Advertisement

02.15.2006 at 06:53AM PST, ID: 21737638
[x]
Attachment Details

Set an image to background / foreground .

Asked by vb_elmar in JavaScript

Tags: background, set, image

Hello,

the script below is a drag and drop script. It has two images (crocodile and viking).

When dragging the viking image, the crocodile image
(unfortunately) is in the foreground.

How can i change the script, so that
- - the currently moved - -
image is in the foreground?

-It should be like this :

Example 1:
When dragging the viking image, the viking image should be
in the foreground, and the crocodile should be in the background.

Example 2:
When dragging the alligator image, the alligator image should be
in foreground, and the viking should be in the background.


<html>
<head>
<title></title>
</head>
<script>

xm = 0;
ym = 0;
M  = false;
window.onload = function(){
     document.onmousedown= function(e){
          if (!e) e = window.event;
          tg = (e.target) ? e.target : e.srcElement
          if(tg.className =="d" && e.button==1){
               M = tg;
               with(M.style){
                    xZ = pixelLeft-xm;
                    yZ = pixelTop-ym;          
               }
               return false;    
          }
               
     }
     document.onmouseup= function(){
          if(M){M = false;}
     }
     document.onmousemove=function(e){          
          if (!e) e = window.event;
          tg = (e.target) ? e.target : e.srcElement
               xm = (e.x || e.clientX);
               ym = (e.y || e.clientY);
               if(M){
                    M.style.pixelLeft=xm+xZ;
                    M.style.pixelTop=ym+yZ;          
                    return false
               }              
     }    
}

</script>


<body oncontextmenu="return false">

<p>
<img src="http://files.opera-info.de/bilder/forum/user/viking.gif" class="d" title="image 1" style="position:absolute;top:150px">
<img src="http://www.walterzorn.de/images/dragdrop/ddalligator.jpg" class="d" title="image 2" style="position:absolute">
</p>
</body>
</html>
Start Free Trial
[+][-]02.15.2006 at 07:17AM PST, ID: 15960893

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.15.2006 at 07:19AM PST, ID: 15960924

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.15.2006 at 08:05AM PST, ID: 15961475

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.15.2006 at 09:05AM PST, ID: 15962312

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.15.2006 at 10:37AM PST, ID: 15963226

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.15.2006 at 02:07PM PST, ID: 15965559

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: JavaScript
Tags: background, set, image
Sign Up Now!
Solution Provided By: pD_EO
Participating Experts: 1
Solution Grade: A
 
 
[+][-]02.15.2006 at 09:24PM PST, ID: 15968300

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32