views:

67

answers:

4

Hello all

I have developed a dragable div with an image inside using jquery. The script is working perfectly in Firefox, chrome but not it IE6. could you please help me to fix this issue

check the web page here : my web page

Thank you very much for your consideration.

A: 

Unless you expect a lot of your visitors to use it - just drop IE6 support. Keeping sites IE6 compatible either increases code redundancy or degrades quality.

Dan Stocker
but here I want to know the solution
milan
Do you have any suggestions ?
milan
this is something of a non-answer
theraccoonbear
@theraccoonbear agreed. -1
Pekka
Solve one problem like this and IE6 persists a little longer - causing unnecessary headache to developers - exactly like in this case. I'm sorry Milan, but there's no good reason to waste time on this, and I'm even more sorry that the others can't see it.
Dan Stocker
@Dan have you ever had a client, or do you just do work for yourself? Most developers, in my experience, do not get to dictate what platforms will be supported. Certainly you can advocate for "No IE6", but suggesting that it can simply be ignored universally strikes me as rather naive.
theraccoonbear
A: 

Since you're already using jQuery, why not use jQuery UI's draggable component? This way, you don't have to deal with all the mouse down calculations. I switched your site's code to use jQuery UI's draggable functionality and it was pretty quick and required a lot less code.

Here's the code I used:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Drag and drop</title>
<style type="text/css"> 
#dv {
             position: absolute;
             cursor: move;
           }  
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"&gt;&lt;/script&gt;
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js"&gt;&lt;/script&gt;
<script language="javascript"> 
    $(document).ready(function() {
        $("#dv").draggable({
            cursor: 'crosshair'
        });
    });
</script>
</head>
<body>

<div id="dv" style="position:absolute;left:300px;top:200px;">
<img src="http://www.mejoyal.com/jquery/drupal.png" />
</div>


</div>
</body>

</html>

Hope this helps!!

David Hoerster
He wants to understand why this doesn't work.
EndangeredMassa
once again, that's not what he asked
theraccoonbear
A: 

I would probably not write the code myself. jQuery UI provides a $(...).draggable() method that should work, and is cross-browser tested. You can even custom build a jQuery UI download that will only include the components you want.

http://jqueryui.com/demos/draggable/

http://jqueryui.com/download

theraccoonbear
He wants to understand why this doesn't work.
EndangeredMassa
no, he wants it fixed. there's a difference.
theraccoonbear
+3  A: 

IE uses clientX and clientY instead of pageX and pageY. Some people fix this by doing the following:

//if IE, then:
if (e.srcElement) {
    e.pageX = oEvent.clientX + document.body.scrollLeft;
    e.pageY = oEvent.clientY + document.body.scrollTop;
}

//rest of event handler goes here
EndangeredMassa
He appears to be using jQuery's event object which normalizes the `pageX pageY` properties. http://api.jquery.com/category/events/event-object/ Although this is the *only* answer that actually attempts to solve the code issue.
patrick dw