473,383 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Targeted Drag and Drop code modification help.


I found some drag and drop code on the web and modified it a little b
taking out some of the stuff I didn't need.

This sample allows you to drag an image in a table to another positio
and swaps the images. Rather than just swap the images I would like t
have it insert the image and move the other images down one position
(or up) What would be even better is to have a radio button to specif
whether you want to swap or insert the image.

This sample has 16 images but eventually I plan for the IMG SRC to com
from a database so there could be many more or even fewer images. I
will always have 4 columns but a varying number of rows depending i
the number of images.

Being new to Javascript I'm not quite sure how to go about it.

The .zip includes the code and 16 small image

+----------------------------------------------------------------
| Attachment filename: drag.zip
|Download attachment: http://www.forum4designers.com/attac...p?postid=95262
+----------------------------------------------------------------

portraitmake
-----------------------------------------------------------------------
Posted via http://www.forum4designers.co
-----------------------------------------------------------------------
View this thread: http://www.forum4designers.com/message27114.htm

Jul 20 '05 #1
1 1825
"portraitmaker" <po*****************@mail.forum4designers.com> wrote in
message news:po*****************@mail.forum4designers.com. ..

I found some drag and drop code on the web and modified it a little by
taking out some of the stuff I didn't need.

This sample allows you to drag an image in a table to another position
and swaps the images. Rather than just swap the images I would like to
have it insert the image and move the other images down one position.
(or up) What would be even better is to have a radio button to specify
whether you want to swap or insert the image.

This sample has 16 images but eventually I plan for the IMG SRC to come
from a database so there could be many more or even fewer images. It
will always have 4 columns but a varying number of rows depending in
the number of images.

Being new to Javascript I'm not quite sure how to go about it.

The .zip includes the code and 16 small images
+----------------------------------------------------------------+
| Attachment filename: drag.zip |
|Download attachment: http://www.forum4designers.com/attachment.php?postid=95262| +----------------------------------------------------------------+

portraitmaker
------------------------------------------------------------------------
Posted via http://www.forum4designers.com
------------------------------------------------------------------------
View this thread: http://www.forum4designers.com/message27114.html


Below is the HTML source for a JigSaw puzzle from
Wrox's Instant IE4 Dynamic HTML Reference (0685).

It used to be on their site at:
http://rapid.wrox.co.uk/books/0685/

It works with 96 images (24 square basic images at every rotation) in a 6x4
table.
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
<HEAD><TITLE>The Jigsaw Example</TITLE></HEAD>

<BODY>

<H3> Move pieces by clicking and dragging. Double-click on a piece to rotate
it.</H3>

<IMG ID="Grid" SRC="jig1.gif" STYLE="position:absolute; top=50; left=310;
width=356; height=237">
<IMG ID="P1" SRC="gogh11.gif" STYLE="position:absolute; top=50; left=20;
width=59; height=59">
<IMG ID="P2" SRC="gogh22.gif" STYLE="position:absolute; top=120; left=20;
width=59; height=59">
<IMG ID="P3" SRC="gogh33.gif" STYLE="position:absolute; top=190; left=20;
width=59; height=59">
<IMG ID="P4" SRC="gogh41.gif" STYLE="position:absolute; top=260; left=20;
width=59; height=59">
<IMG ID="P5" SRC="gogh54.gif" STYLE="position:absolute; top=330; left=20;
width=59; height=59">
<IMG ID="P6" SRC="gogh61.gif" STYLE="position:absolute; top=400; left=20;
width=59; height=59">
<IMG ID="P7" SRC="gogh72.gif" STYLE="position:absolute; top=50; left=90;
width=59; height=59">
<IMG ID="P8" SRC="gogh83.gif" STYLE="position:absolute; top=120; left=90;
width=59; height=59">
<IMG ID="P9" SRC="gogh91.gif" STYLE="position:absolute; top=190; left=90;
width=59; height=59">
<IMG ID="P10" SRC="gogh103.gif" STYLE="position:absolute; top=260; left=90;
width=59; height=59">
<IMG ID="P11" SRC="gogh113.gif" STYLE="position:absolute; top=330; left=90;
width=59; height=59">
<IMG ID="P12" SRC="gogh121.gif" STYLE="position:absolute; top=400; left=90;
width=59; height=59">
<IMG ID="P13" SRC="gogh133.gif" STYLE="position:absolute; top=50; left=160;
width=59; height=59">
<IMG ID="P14" SRC="gogh141.gif" STYLE="position:absolute; top=120; left=160;
width=59; height=59">
<IMG ID="P15" SRC="gogh154.gif" STYLE="position:absolute; top=190; left=160;
width=59; height=59">
<IMG ID="P16" SRC="gogh163.gif" STYLE="position:absolute; top=260; left=160;
width=59; height=59">
<IMG ID="P17" SRC="gogh172.gif" STYLE="position:absolute; top=330; left=160;
width=59; height=59">
<IMG ID="P18" SRC="gogh182.gif" STYLE="position:absolute; top=400; left=160;
width=59; height=59">
<IMG ID="P19" SRC="gogh193.gif" STYLE="position:absolute; top=50; left=230;
width=59; height=59">
<IMG ID="P20" SRC="gogh204.gif" STYLE="position:absolute; top=120; left=230;
width=59; height=59">
<IMG ID="P21" SRC="gogh212.gif" STYLE="position:absolute; top=190; left=230;
width=59; height=59">
<IMG ID="P22" SRC="gogh223.gif" STYLE="position:absolute; top=260; left=230;
width=59; height=59">
<IMG ID="P23" SRC="gogh233.gif" STYLE="position:absolute; top=330; left=230;
width=59; height=59">
<IMG ID="P24" SRC="gogh241.gif" STYLE="position:absolute; top=400; left=230;
width=59; height=59">

</BODY>

<SCRIPT LANGUAGE=JavaScript>

var strImgDragging = null; // the global 'piece being moved' variable

function mouseDownEvent() // set the jigsaw piece to be moved
{
strID = event.srcElement.id;
if (strID.indexOf("P") != -1) // if this is a jigsaw piece
{
strImgDragging = strID // save the ID in a global variable
// bring the piece to the top of the z-order
document.all[strImgDragging].style.zIndex = 1
window.status = "Drag this piece onto the grid and release the mouse to
position it ..."
}
else
strImgDragging = null; // set global variable to null
}
function mouseMoveEvent() // move the jigsaw piece
{
if (strImgDragging != null)
{
// move the image to the new position
// assume the mouse pointer is in middle of image
document.all[strImgDragging].style.pixelLeft = event.x - 30;
document.all[strImgDragging].style.pixelTop = event.y - 30;
}

// prevent event being handled elsewhere and the default action
event.cancelBubble = true;
event.returnValue = false;
}
function mouseUpEvent() // place the jigsaw piece on the grid
{
if (strImgDragging != null)
{
// stop dragging, and position the piece in line with grid.
posLeft = Math.floor((document.all[strImgDragging].style.pixelLeft -
280) / 59);
posTop = Math.floor((document.all[strImgDragging].style.pixelTop - 20) /
59);
if (posLeft >= 0 && posTop >= 0)
{
document.all[strImgDragging].style.pixelLeft = (posLeft * 59) + 311;
document.all[strImgDragging].style.pixelTop = (posTop * 59) + 51;
}

// return the piece to the lower z-order position
document.all[strImgDragging].style.zIndex = 0;

// reset the global 'dragging' variable
strImgDragging = null;
window.status = "Click on a jigsaw piece and drag it onto the grid ..."

// prevent event being handled elsewhere and the default action
event.cancelBubble = true;
event.returnValue = false;
}
}

function dblClickEvent() // rotate the jigsaw piece
{
objImage = event.srcElement; // get a reference to the image
strImageID = objImage.id; // get the ID of the image

// if it's a jigsaw piece then rotate it
if (strImageID.indexOf("P") != -1)
{
strSrc=objImage.src // get the image file name

// extract just the image number as a string
intStart = strSrc.indexOf("\gogh");
if (intStart != -1)
strSrc = strSrc.substring(intStart + 4);
intEnd = strSrc.indexOf(".");
if (intEnd != -1)
strSrc = strSrc.substring(0, intEnd);

//split into image and attitude numbers
strImgNum = strSrc.substring(0, strSrc.length -1);
strAttNum = strSrc.substring(strSrc.length - 1, strSrc.length);

// calculate the new image attitude number
intAttNum = strAttNum.valueOf();
intAttNum ++;
if (intAttNum > 4) intAttNum = 1;
strAttNum = intAttNum.toString();

// create and assign the new image name
objImage.src = "gogh" + strImgNum + strAttNum + ".gif";

}
// prevent event being handled elsewhere and the default action
event.cancelBubble = true;
event.returnValue = false;
}

document.ondblclick=dblClickEvent;
document.onmousedown=mouseDownEvent;
document.onmousemove=mouseMoveEvent;
document.onmouseup=mouseUpEvent;
</SCRIPT>
</HTML>
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Wang, Jay | last post by:
Hello, all, I would like to enable some text between <SPAN url="http://www.testserver.com/">WORD TO BE DRAGGED </SPAN>. I put some javascript and it will extract http://www.testserver.com/ from...
0
by: Lauren Quantrell | last post by:
I'm trying to drop a file from Windows Explorer (or desktop, etc.) onto a field in Access2K and capture the full file path. I found an posting below that says this is possible but I cannot...
8
by: WindAndWaves | last post by:
Hi everyone, Has anyone got any experience with drop and drag in Access? I would like to make a calendar style form where my users can drop and drag appointments.... I am using Access 2003...
6
by: Wei Junping | last post by:
Hi, all. I want my program act as an drag source and do drag and drop asynchronously. So, I created a class CDataObject which implements interfaces IDataObject and IAsyncOperation. To begin drag...
6
by: jojobar | last post by:
Hello, I look at the asp.net 2.0 web parts tutorial on the asp.net web site. I tried to run it under firefox browser but it did not run. If I want to use this feature in a commercial product...
4
by: kemal asad | last post by:
how can i create a vb application where i can drag and drop ( with a move caracteristic) email from outlook, into my application( email viewer). thanks, any help is welcome, samples a great way of...
1
by: Terry Olsen | last post by:
My first time using TreeViews. I have TreeView1 set up to display my directory structure just like Windows Explorer. I can drag & drop files and folders over to TreeView2. I can re-arrange the...
2
by: TarheelsFan | last post by:
I am having problems with drag and drop into a listview. I am able to drag and drop items from within the listview, as well as drag items from the listview and drop into a picturebox. However, I...
5
by: empiresolutions | last post by:
Hello Fellow Developers, I am using the awesome drag and drop script found at http://script.aculo.us/. I have also added a modification that interacts to a db for reordering upon release of a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.