Solved

OnDrag Cursor

Posted on 2004-03-25
14
917 Views
Last Modified: 2008-02-07
I want to use the OnDrag event trigger on an object to where the cursor style during the drag is as I choose. Currently, when you drag an object the cursor style changes to "not-allowed". I would much rather it be "default" or perhaps "crosshair".

Can this be done in Internet Explorer 6? If so, How?
0
Comment
Question by:jasons016
  • 6
  • 3
  • 3
  • +1
14 Comments
 
LVL 33

Expert Comment

by:sajuks
ID: 10684592
//Zvonkos script
<script>
function move() {
  thing.style.cursor='hand';
  thing.style.left = window.event.x;
  thing.style.top = window.event.y;
  return false
}
</script>

<img src="http://www.experts-exchange.com/images/greyLogo.jpg" style="position:absolute" id=thing ondragstart="return move()">
0
 
LVL 33

Expert Comment

by:sajuks
ID: 10684595

<script>
function move() {
  thing.style.cursor="crosshair"; // use the style you prefer
  thing.style.left = window.event.x;
  thing.style.top = window.event.y;
  return false
}
</script>

<img src="http://www.experts-exchange.com/images/greyLogo.jpg" style="position:absolute" id=thing ondragstart="return move()">
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10684774
How about this:

<img src="http://www.experts-exchange.com/images/greyLogo.jpg" id="img1" onDragStart="return false">

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10684834
And if you need the drag functionality, then use this:

<img src="http://www.experts-exchange.com/images/greyLogo.jpg" id="img1" onDragOver="return false" onDragStart="yourDrag()">

0
 
LVL 1

Author Comment

by:jasons016
ID: 10692999
I thought of those things and tried them before I posted the question. You see, if I return false on OnDrag, OnDragOver, or OnDragStart, then the drag does not work. If I set the cursor to anything inside of any of those event functions, then Internet Explorer overrides it so that it is still 'not-allowed.'

My question stands.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10693908
Show us your code or test this one:

<script>
function yourDragStart(){
  window.status = "Start."
  document.body.ondragover = yourDragOver;
}
function yourDragOver(){
  window.status = event.x+"  "+event.y;
  return true;
}
</script>
<body>
<img src="http://www.experts-exchange.com/images/greyLogo.jpg" id="img1" onDragOver="return yourDragOver()" onDragStart="yourDragStart()">
</body>




0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10693912
Sorry, check this:

<script>
function yourDragStart(){
  window.status = "Start."
  document.body.ondragover = yourDragOver;
}
function yourDragOver(){
  window.status = event.x+"  "+event.y;
  return false;
}
</script>
<body>
<img src="http://www.experts-exchange.com/images/greyLogo.jpg" id="img1" onDragOver="return yourDragOver()" onDragStart="yourDragStart()">
</body>

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:jasons016
ID: 10696164
Returning false on OnDragOver makes the cursor not 'not-allowed', however, it does not solve my problem. I'd much rather the cursor be 'default' or 'crosshair'.

Here, I will show you what I have.

[clip from "script.js"]
function track_mouse()
{
      // The following statement does not change the cursor to 'hand'
      // document.all.bpix.style.cursor='hand';

      // The following statements (supposedly) work on JScript, but not IE
      // window.event.dataTransfer.effectAllowed="none";
      // window.event.dataTransfer.dropEffect="none";

      document.all.bpix.style.left=window.event.clientX-(document.all.bpix.width/2);
      document.all.bpix.style.top=window.event.clientY-(document.all.bpix.height/2);
      
      return true;
}
[/clip]

[clip from "index.html"]
<img src="blu_pix.jpg" style="position: absolute; cursor: default;" width="30" height="30" id="bpix" OnDrag="return track_mouse();" OnDragOver="return false;" />
[/clip]
0
 
LVL 12

Accepted Solution

by:
lil_puffball earned 500 total points
ID: 10696299
Try this script:

<script>
var drag=false;
function track_mouse()
{
     // The following statements (supposedly) work on JScript, but not IE
     // window.event.dataTransfer.effectAllowed="none";
     // window.event.dataTransfer.dropEffect="none";

     document.all.bpix.style.left=window.event.clientX-(document.all.bpix.width/2);
     document.all.bpix.style.top=window.event.clientY-(document.all.bpix.height/2);
}
</script>




<body onmousemove="if(drag){track_mouse();}">

<img src="blu_pix.jpg" style="position: absolute; cursor: default;" width="30" height="30" id="bpix" onmousedown="drag=true;this.style.cursor='crosshair';" onmouseup="drag=false;this.style.cursor='default';" unselectable=on>
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10696303
Simmelar idea:


<script>
function lock_mouse(theImg){
     theImg.style.cursor='hand';
     theImg.follow = true;    
}
function track_mouse(theImg){
     if(theImg.follow){
       theImg.style.left=window.event.clientX-(theImg.width/2);
       theImg.style.top=window.event.clientY-(theImg.height/2);
     }
}
function release_mouse(theImg){
     theImg.style.cursor='crosshair';
     theImg.follow = false;    
}
</script>
<body>
<img src="http://www.experts-exchange.com/images/pe/143475.jpg" style="position: absolute; cursor: crosshair;" width="30" height="30" id="bpix" OnMouseDown="lock_mouse(this);" OnMouseMove="track_mouse(this);" onMouseUp="release_mouse(this)" onDragStart="return false" />
</body>

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10696308
Please note: my method can move several images.
0
 
LVL 1

Author Comment

by:jasons016
ID: 10696372
Thank you both very much.
0
 
LVL 12

Expert Comment

by:lil_puffball
ID: 10696411
Thanks for the points and the A. :)
0
 
LVL 12

Expert Comment

by:lil_puffball
ID: 10696422
By the way, to Zvonko:
It is better to put the onmousemove in the body tag. Because if you put the onmousemove in the img tag, and move the image very quickly, your mouse is no longer moving above the image, and the image won't be draggable anymore. I came across this problem while writing some other drag scripts a while ago. :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now