Solved

OnDrag Cursor

Posted on 2004-03-25
14
921 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
where is team.js? 3 30
jQuery force form POST 7 42
2 separate CSS animations 2 16
maven not picking latest jar instead picking old jar from .m2 12 17
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

791 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