Results 1 to 6 of 6

Thread: How to get this "cool" effect?

  1. #1
    Join Date
    Jun 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to get this "cool" effect?

    Pls go to this page

    http://www.mixonic.com/

    In this page, once you add a text, its displayed on the CD. Now you can move the text around the CD by dragging the text with your mouse. I need a similar effect (dragging text, picture with mouse) for one of my application that im working on.

    PLEASE post me a link for a tutor which shows how this is done or pls post a code/script.

    Thanks in advance.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I'm not sure how they did that but, I don't like it because the text doesn't go exactly where I drag it to and everything disappears while I am dragging it. This link has a much better solution that may be adaptable to whatever your actual purpose (you weren't real clear about that) is:

    http://www.walterzorn.com/dragdrop/dragdrop_e.htm
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You need to capture the mouse event, then set the element's left and top properties to the x and y of the mouse event, respectively.

    HTML Code:
    <html>
    <head>
    <title>
    Drag
    </title>
    <style type="text/css">
    #draggable {
    	position: absolute;
    	top: 0;
    	left: 0;
    }
    </style>
    <script type="text/javascript">
    <!--
    drag = false;
    
    function mdHandle() {
    	drag = !drag;
    }
    
    function mvHandle(evt) {
    	if(drag) {
    		obj = document.getElementById("draggable");
    		obj.style.top = (evt.pageY - 88) + "px";
    		obj.style.left = (evt.pageX - 88) + "px";
    	}
    }
    //-->
    </script>
    </head>
    <body onmousemove="mvHandle(event);">
    <div id="draggable" onmousedown="mdHandle();">
    <img src="http://www.grand-illusions.com/images/moonphoto.jpg"/>
    </div>
    </body>
    </html>
    Adjust as needed.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Twey
    You need to capture the mouse event, then set the element's left and top properties to the x and y of the mouse event, respectively.
    Good idea but, your execution is jerky under Mozilla and error riden under IE6.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jun 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks. But i need to drag the element (text or image) within a boundary - square or circle. How do get this done. The examples i see on walterzorn is good, but i can drag the image through the whole page and not within a limited boundary

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The script has optional parameters for setting top, bottom, left and right limits to the dragability. See this page for a demo and explanation of this and many other options:

    http://www.walterzorn.com/dragdrop/commands_e.htm
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •