Solved

OnDrag Cursor

Posted on 2004-03-25
14
922 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

756 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