Log in

View Full Version : Drag multiple images



Chaim
07-20-2009, 04:29 PM
I am working on a math game which requires the user to select multiple images and drag them off a scale and drop them. I am using the Dom drag and drop Script which does one image drag perfectly. Can any one suggest a solution to select multiple images and drag them simultaneously. The page is at http://koltora.com/math/ Thanks Chaim

vwphillips
07-21-2009, 09:12 AM
how do you select the multiple images?

Chaim
07-26-2009, 07:08 PM
The user selects the images with the left mouse buttton, holding down the control key.

vwphillips
07-27-2009, 09:18 AM
<html>
<head>
<style type="text/css">
/*<![CDATA[*/
.drag {
position:absolute;left:100px;top:100px;width:50px;height:50px;background-Color:red;
}

/*]]>*/
</style><script type="text/javascript">
/*<![CDATA[*/
// Drag and Drop (14-April-2009)
// by Vic Phillips http://www.vicsjavascripts.org.uk/

// To Drag and drop an element.
// The drag may be executed from the draggable object or a nested element(drag panel)
// Minimum and maximum drag limits may be specified for both 'X' and 'Y' coordinates.
// Specified functions may be called on mousedown, move or mouse up of the object.
//
// There may be as many applications as required on a page.

// ****** Application Notes

// ***** The HTML and CSS Code
//
// The drag objects position must assigned as 'relative' or absolute'
// and the 'left', top' and 'z-Index' assigned by the drag objects style class or inline style


// ***** Initialising the Script
//
// The script would normally initialised by a BODY or window event call assign the instance of the script to a variable.
// e.g.
// var oop=new zxcDrag(document.getElementById('tst'),false,'xy',[0,300,0,250])
// where:
// parameter 1 = the object to activate drag on mousedown. (object)
// parameter 2 = the object to dragged on mousemove. (object, or false to default to parameter 1)
// parameter 3 = (optional) a string containing 'x' to drag x and/or 'y' to drag y. (string, default 'xy')
// parameter 4 = (optional) an array defining the minimum and maximum x and y coordinates (array, default [])
// where:
// field 0 = the minimum x cordinate. (digits, null = not set)
// field 1 = the maximum x cordinate. (digits, null = not set)
// field 2 = the minimum y cordinate. (digits, null = not set)
// field 3 = the maximum y cordinate. (digits, null = not set)
// parameter 4 = (optional) a function name to be called on mouseup(see Note 2). (function object)
// parameter 5 = (optional) a function name to be called on mousemove(see Note 2). (function object)
// parameter 6 = (optional) a function name to be called on mousedown(see Note 2). (function object)

// Note 1:
// On mousedown of the object the object z_index is increased by 10.
// On the mouseup the z-Index is restored to the original z-Index.

// Note 2:
// When a function is called the zxcDrag function is passed to the function.
// The drag object may be access by argument[0].dobj, and the event as argument[1].
// e.g.
// function Test(obj,evt){
// alert(obj.dobj);
// alert(evt.type);
// }


// Functional Code Size 2.17K

// ****** Functional Code - NO NEED to Change

function zxcDrag(obj,root,dxy,mm,uf,mf,df){
this.dobj=root?root:obj;
mm=mm||['x','x','y','y'];
dxy=(dxy||'xy').toLowerCase();
this.dx=dxy.indexOf('x')>-1?true:false;
this.dy=dxy.indexOf('y')>-1?true:false;
this.mm=[typeof mm[0]=='number'?mm[0]:-100000,typeof mm[1]=='number'?mm[1]:100000,typeof mm[2]=='number'?mm[2]:-100000,typeof mm[3]=='number'?mm[3]:100000];
this.df=df||false; this.mf=mf||false; this.uf=uf||false;
this.addevt(obj||root,'mousedown','down');
this.addevt(document,'mousemove','move');
this.addevt(document,'mouseup','up');
return this;
}

zxcDrag.prototype.down=function(ev){
document.onselectstart=function(event){ window.event.returnValue=false; }
this.lastXY=[ev.clientX,ev.clientY];
this.drag=true;
this.dobj.style.zIndex=zxcLTZ(this.dobj,'z-Index')+10+'';
this.pos=[zxcLTZ(this.dobj,'left'),zxcLTZ(this.dobj,'top')];
if (this.df) this.df(this,ev);
if (!window.event) ev.preventDefault();
return false;
}

zxcDrag.prototype.move=function(ev){
if (this.drag){
var mse=[ev.clientX,ev.clientY];
this.pos=[Math.min(Math.max(this.mm[0],this.pos[0]+mse[0]-this.lastXY[0]),this.mm[1]),Math.min(Math.max(this.mm[2],this.pos[1]+mse[1]-this.lastXY[1]),this.mm[3])];
if (this.dx) this.dobj.style.left=this.pos[0]+'px';
if (this.dy) this.dobj.style.top=this.pos[1]+'px';
this.lastXY=mse;
if (this.mf) this.mf(this,ev);
}
if (!window.event) ev.preventDefault();
return false;
}

zxcDrag.prototype.up=function(ev){
if (this.drag){
this.drag=false;
this.dobj.style.zIndex=zxcLTZ(this.dobj,'z-Index')-10+'';
if (this.uf) this.uf(this,ev);
document.onselectstart=null;
}
}

zxcDrag.prototype.addevt=function(o,t,f){
var oop=this;
if (o.addEventListener) o.addEventListener(t,function(e){ return oop[f](e);}, false);
else if (o.attachEvent) o.attachEvent('on'+t,function(e){ return oop[f](e); });
else {
var prev=o['on'+t];
if (prev) o['on'+t]=function(e){ prev(e); oop[f](e); };
else o['on'+t]=o[f];
}
}

function zxcLTZ(obj,p){
if (obj.currentStyle) return parseInt(obj.currentStyle[p.replace(/-/g,'')]);
return parseInt(document.defaultView.getComputedStyle(obj,null).getPropertyValue(p.toLowerCase()));
}


/*]]>*/
</script>

<script type="text/javascript">
/*<![CDATA[*/

function Init(){
var ds=zxcByClassName('drag')
for (var oop,z0=0;z0<ds.length;z0++){
oop=new zxcDrag(ds[z0],false,'xy',null,DragRemove,null,DragAdd);
}
}

function zxcByClassName(nme,el,tag){
if (typeof(el)=='string') el=document.getElementById(el);
el=el||document;
for (var tag=tag||'*',reg=new RegExp('\\b'+nme+'\\b'),els=el.getElementsByTagName(tag),ary=[],z0=0; z0<els.length;z0++){
if(reg.test(els[z0].className)) ary.push(els[z0]);
}
return ary;
}

var DObjs=[]

function DragAdd(oop,e){
if (e.ctrlKey){
DObjs.push(oop);
oop.drag=false;
}
else {
for (var z0=0;z0<DObjs.length;z0++){
if (DObjs[z0]!=oop) DObjs[z0].down(e);
}
}
}

function DragRemove(oop,e){
if (!e.ctrlKey) DObjs=[];


}
/*]]>*/
</script></head>

<body onload="Init();">

<div class="drag" ></div>
<div class="drag" style="left:300px;"></div>
</body>
</html>

Chaim
07-27-2009, 10:29 PM
You are amazing!
Thank you so much for helping me.
Your code works in Firefox but it is unclear when the user is clicking the images.
Is there a way to indicate that the image was chosen. Like a line around the image when it is selected.
Unfortunately the code did not work at all in Chrome
In IE8 it says out of memory line 126
Where in the code do I substitute my images for the boxes you drew.
Thanks again

vwphillips
07-28-2009, 08:38 AM
to add a border


function DragAdd(oop,e){
if (e.ctrlKey){
DObjs.push(oop);
oop.drag=false;
oop.dobj.style.border='solid black 1px';
}
else {
for (var z0=0;z0<DObjs.length;z0++){
if (DObjs[z0]!=oop) DObjs[z0].down(e);
}
}
}

function DragRemove(oop,e){
if (!e.ctrlKey){
for (var z0=0;z0<DObjs.length;z0++){
DObjs[z0].dobj.style.borderWidth='0px';
}
DObjs=[];
}
}





Unfortunately the code did not work at all in Chrome
In IE8 it says out of memory line 126


I tested in Chrome and IE7 and it was OK

provide a link to your test page so I can check


Where in the code do I substitute my images for the boxes you drew.


give your images a class name of drag and

// ***** The HTML and CSS Code
//
// The drag objects position must assigned as 'relative' or absolute'
// and the 'left', top' and 'z-Index' assigned by the drag objects style class or inline style

Chaim
07-28-2009, 10:45 PM
Sorry for my mistake. I tested it locally. When I uploaded it to www.koltora.com/drop.html it works in Firefox and Chrome but I still get the out of memory line 126 error in IE8. Could I ask you to give me a complete example of the code - integrating you box outline code over an example image. Thank you again for your wisdom and patience.

vwphillips
07-29-2009, 10:05 AM
http://www.vicsjavascripts.org.uk/DragDrop/090728A.htm

the ammended Drag & Drop script has been ammended to accept 'right' and 'bottom'

I am reluctent to install IE8

Chaim
07-29-2009, 01:07 PM
I understand your reluctance about IE8. They may eventually join the standards club. I put your code on my site http://koltora.com/math/ and it works perfectly on Firefox and Chrome. It has a little delay in the initial drag stage but that is not significant. Thank you again. I searched for a solution for many hours for this problem and could not find anyone to address the issue of multiple drag and drop. You were ever so kind to even write the script. Much appreciation and many thanks from a novice to a true professional. Chaim

vwphillips
08-03-2009, 09:46 AM
from pm


Thanks again. I want to clone my images. So that when the user picks a pawn for example another pawn appears underneath and can also be selected.
I have done this in a simple way by copying and renaming the images *b.gif. As you can see in the script at my site http://koltora.com/math/
Is there a simple way to make an infinite number of image by writing a formula?
Forward Message





.........

function Clone(cls){
var ds=zxcByClassName(cls)
for (var oop,z0=0;z0<ds.length;z0++){
ds[z0].onmousedown=function(){ MakeClone(this); }
}
}

function MakeClone(obj){
var e=window.event||arguments.callee.caller.arguments[0];
var clone=obj.cloneNode(true);
document.body.appendChild(clone);
clone.style.zIndex=zxcLTZ(obj,'z-Index')+1;
var oop=new zxcDrag(clone,false,'xy',null,DragRemove,null,DragAdd);
oop.down(e);
}
/*]]>*/
</script>
</head>

<body bgcolor="#FFFF00" onload="Init();Clone('clone');">
<img class="clone" id="w01a" src="http://koltora.com/math/w01.gif" style="position:absolute; left:850px; top:100px" />
<img class="clone" id="b01a" src="http://koltora.com/math/b01.gif" style="position:absolute; left:750px; top:100px" />
.........


also try changing this function for your IE8 problem


zxcDrag.prototype.down=function(ev){
if(!this.drag){
document.onselectstart=function(event){ window.event.returnValue=false; }
this.lastXY=[ev.clientX,ev.clientY];
this.drag=true;
this.dobj.style.zIndex=zxcLTZ(this.dobj,'z-Index')+10+'';
this.pos=[zxcLTZ(this.dobj,this.xmde),zxcLTZ(this.dobj,this.ymde)];
if (this.df) this.df(this,ev);
}
if (!window.event) ev.preventDefault();
return false;
}

Chaim
08-03-2009, 12:22 PM
You are amazing! Both scripts work. Infinite images + and smooth dragging + also works in IE8.

Chaim
08-04-2009, 04:20 AM
IE8 and Firefox are working fine. Now Google Chrome is giving me a blue box when I select an object. I added some more features: Refresh and a question box at:
http://www.koltora.com/math/ Could you have a look? Thanks

vwphillips
08-04-2009, 10:54 AM
try


<script type="text/javascript">
/*<![CDATA[*/
// Drag and Drop (04-August-2009)
// by Vic Phillips http://www.vicsjavascripts.org.uk/

// To Drag and drop an element.
// The drag may be executed from the draggable object or a nested element(drag panel)
// Minimum and maximum drag limits may be specified for both 'X' and 'Y' coordinates.
// Specified functions may be called on mousedown, move or mouse up of the object.
//
// There may be as many applications as required on a page.

// ****** Application Notes

// ***** The HTML and CSS Code
//
// The drag objects position must assigned as 'relative' or absolute'
// and the 'left', top' and 'z-Index' assigned by the drag objects style class or inline style.
// Options allow the use of 'right' and 'bottom' in place of 'left' and top' respectively.

// ***** Initialising the Script
//
// The script would normally initialised by a BODY or window event call assign the instance of the script to a variable.
// e.g.
// var oop=new zxcDrag(document.getElementById('tst'),false,'xy',[0,300,0,250])
// where:
// parameter 1 = the object to activate drag on mousedown. (object)
// parameter 2 = (optional) the object to dragged on mousemove. (object, default to parameter 1 object)
// parameter 3 = (optional) a string containing 'x' to drag x and/or 'y' to drag y. (string, default 'xy')
// the default style positions are 'left' and 'top'
// to use 'right' include 'r', to use 'bottom' include 'b'.
// parameter 4 = (optional) an array defining the minimum and maximum x and y coordinates (array, default [])
// where:
// field 0 = the minimum x cordinate. (digits, null = not set)
// field 1 = the maximum x cordinate. (digits, null = not set)
// field 2 = the minimum y cordinate. (digits, null = not set)
// field 3 = the maximum y cordinate. (digits, null = not set)
// parameter 4 = (optional) a function name to be called on mouseup(see Note 2). (function object)
// parameter 5 = (optional) a function name to be called on mousemove(see Note 2). (function object)
// parameter 6 = (optional) a function name to be called on mousedown(see Note 2). (function object)

// Note 1:
// On mousedown of the object the object z_index is increased by 10.
// On the mouseup the z-Index is restored to the original z-Index.

// Note 2:
// When a function is called the zxcDrag function is passed to the function.
// The drag object may be access by argument[0].dobj, and the event as argument[1].
// e.g.
// function Test(obj,evt){
// alert(obj.dobj);
// alert(evt.type);
// }


// Functional Code Size 2.85K

// ****** Functional Code - NO NEED to Change

function zxcDrag(obj,root,dxy,mm,uf,mf,df){
this.dobj=root?root:obj;
mm=mm||['x','x','y','y'];
dxy=(dxy||'xy').toLowerCase();
this.dx=dxy.indexOf('x')>-1?true:false;
this.dy=dxy.indexOf('y')>-1?true:false;
this.xmde=dxy.indexOf('r')<0?'left':'right';
this.ymde=dxy.indexOf('b')<0?'top':'bottom';
this.mm=[typeof mm[0]=='number'?mm[0]:-100000,typeof mm[1]=='number'?mm[1]:100000,typeof mm[2]=='number'?mm[2]:-100000,typeof mm[3]=='number'?mm[3]:100000];
this.df=df||false; this.mf=mf||false; this.uf=uf||false;
this.addevt(obj||root,'mousedown','down');
this.addevt(document,'mousemove','move');
this.addevt(document,'mouseup','up');
return this;
}

zxcDrag.prototype.down=function(ev){
if (!this.drag){
document.onselectstart=function(event){ window.event.returnValue=false; };
this.lastXY=[ev.clientX,ev.clientY];
this.drag=true;
this.dobj.style.zIndex=zxcLTZ(this.dobj,'z-Index')+10+'';
this.pos=[zxcLTZ(this.dobj,this.xmde),zxcLTZ(this.dobj,this.ymde)];
if (this.df) this.df(this,ev);
}
if (ev.target) ev.preventDefault();
return false;
}

zxcDrag.prototype.move=function(ev){
if (this.drag){
var mse=[ev.clientX,ev.clientY];
this.pos=[Math.min(Math.max(this.mm[0],this.pos[0]+(mse[0]-this.lastXY[0])*(this.xmde=='left'?1:-1)),this.mm[1]),Math.min(Math.max(this.mm[2],this.pos[1]+(mse[1]-this.lastXY[1])*(this.ymde=='top'?1:-1)),this.mm[3])];
if (this.dx) this.dobj.style[this.xmde]=this.pos[0]+'px';
if (this.dy) this.dobj.style[this.ymde]=this.pos[1]+'px';
this.lastXY=mse;
if (this.mf) this.mf(this,ev);
}
if (ev.target) ev.preventDefault();
return false;
}

zxcDrag.prototype.up=function(ev){
if (this.drag){
this.drag=false;
this.dobj.style.zIndex=zxcLTZ(this.dobj,'z-Index')-10+'';
if (this.uf) this.uf(this,ev);
document.onselectstart=null;
}
}

zxcDrag.prototype.addevt=function(o,t,f){
var oop=this;
if (o.addEventListener) o.addEventListener(t,function(e){ return oop[f](e);}, false);
else if (o.attachEvent) o.attachEvent('on'+t,function(e){ return oop[f](e); });
else {
var prev=o['on'+t];
if (prev) o['on'+t]=function(e){ prev(e); oop[f](e); };
else o['on'+t]=o[f];
}
}

function zxcLTZ(obj,p){
if (obj.currentStyle) return parseInt(obj.currentStyle[p.replace(/-/g,'')],10);
return parseInt(document.defaultView.getComputedStyle(obj,null).getPropertyValue(p.toLowerCase()),10);
}

function zxcCkEventObj(e,p){
if (!e) var e=window.event;
e.cancelBubble=true;
if (e.stopPropagation) e.stopPropagation();
if (e.target) eobj=e.target;
else if (e.srcElement) eobj=e.srcElement;
if (eobj.nodeType==3) eobj=eobj.parentNode;
var eobj=(e.relatedTarget)?e.relatedTarget:(e.type=='mouseout')?e.toElement:e.fromElement;
if (!eobj||eobj==p) return false;
while (eobj.parentNode){
if (eobj==p) return false;
eobj=eobj.parentNode;
}
return true;
}


/*]]>*/
</script>

Chaim
08-07-2009, 09:17 AM
Is there a way to refresh only the game portion of the web page? If I refresh the whole page the questions also reset back to the first question.
I would like the user to be able to reset the board. Also when the user presses the next question the next question should appear with a new board. http://koltora.com/math/
Thanks again Chaim

vwphillips
08-07-2009, 01:20 PM
<script type="text/javascript">

/***********************************************
* DHTML slideshow script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice must stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var photos=new Array()
var photoslink=new Array()
var which=0

//define images. You can have as many as you want:
photos[0]="http://koltora.com/math/photo_i.jpg"
photos[1]="http://koltora.com/math/photo1.jpg"
photos[2]="http://koltora.com/math/photo2.jpg"
photos[3]="http://koltora.com/math/photo3.jpg"
photos[4]="http://koltora.com/math/photo4.jpg"
photos[5]="http://koltora.com/math/photo5.jpg"
photos[6]="http://koltora.com/math/photo6.jpg"
photos[7]="http://koltora.com/math/photo7.jpg"
photos[8]="http://koltora.com/math/photo8.jpg"
photos[9]="http://koltora.com/math/photo9.jpg"
photos[10]="http://koltora.com/math/photo10.jpg"
photos[11]="http://koltora.com/math/photo11.jpg"
photos[12]="http://koltora.com/math/photo12.jpg"
photos[13]="http://koltora.com/math/photo13.jpg"
photos[14]="http://koltora.com/math/photo14.jpg"
photos[15]="http://koltora.com/math/photo_e.jpg"

//Specify whether images should be linked or not (1=linked)
var linkornot=0

//Set corresponding URLs for above images. Define ONLY if variable linkornot equals "1"
photoslink[0]=""
photoslink[1]=""
photoslink[2]=""

//do NOT edit pass this line

var preloadedimages=new Array()
for (i=0;i<photos.length;i++){
preloadedimages[i]=new Image()
preloadedimages[i].src=photos[i]
}


function applyeffect(){
if (document.all && photoslider.filters){
photoslider.filters.revealTrans.Transition=Math.floor(Math.random()*23)
photoslider.filters.revealTrans.stop()
photoslider.filters.revealTrans.apply()
}
}



function playeffect(){
if (document.all && photoslider.filters)
photoslider.filters.revealTrans.play()
}

function keeptrack(){
window.status="Image "+(which+1)+" of "+photos.length
}


function backward(){
if (which>0){
Reset();
which--
applyeffect()
document.images.photoslider.src=photos[which]
playeffect()
keeptrack()
}
}

function forward(){
if (which<photos.length-1){
Reset();
which++
applyeffect()
document.images.photoslider.src=photos[which]
playeffect()
keeptrack()
}
}

function transport(){
window.location=photoslink[which]
}

function Reset(){
for (var z0=0;z0<CAry.length;z0++){
CAry[z0].parentNode.removeChild(CAry[z0]);
}
CAry=[];
}

</script>



function Clone(cls){
var ds=zxcByClassName(cls)
for (var oop,z0=0;z0<ds.length;z0++){
ds[z0].onmousedown=function(){ MakeClone(this); }
}
}

var CAry=[];

function MakeClone(obj){
var e=window.event||arguments.callee.caller.arguments[0];
var clone=obj.cloneNode(true);
document.body.appendChild(clone);
CAry.push(clone);
clone.style.zIndex=zxcLTZ(obj,'z-Index')+1;
var oop=new zxcDrag(clone,false,'xy',null,DragRemove,null,DragAdd);
oop.down(e);
}



<input type="button" name="" value="Reset" onclick="Reset();" />

Chaim
08-07-2009, 03:11 PM
I am having trouble integrating the code in the page properly. I feel so stupid for asking, but could you integrate it.

vwphillips
08-08-2009, 10:41 AM
http://www.vicsjavascripts.org.uk/DragDrop/090808A.htm

Chaim
08-08-2009, 07:04 PM
What can I say..... Thanks, Thanks, Thanks - Chaim

Chaim
08-13-2009, 03:55 AM
Dear Vic, I need a function to delete selected images that are chosen with ctrl + mouse click. Could you solve this one. Thanks Chaim

vwphillips
08-13-2009, 07:53 AM
// modified function
function MakeClone(obj){
var e=window.event||arguments.callee.caller.arguments[0];
var clone=obj.cloneNode(true);
document.body.appendChild(clone);
CAry.push(clone);
clone.style.zIndex=zxcLTZ(obj,'z-Index')+1;
clone.onclick=function(){ RemoveClone(this); }
var oop=new zxcDrag(clone,false,'xy',null,DragRemove,null,DragAdd);
oop.down(e);
}
// new function
function RemoveClone(obj){
var e=window.event||arguments.callee.caller.arguments[0];
if (e.ctrlKey){
obj.parentNode.removeChild(obj)
}
}

Chaim
08-13-2009, 10:58 AM
Sorry I was not clear.
After the pawns, number squares and/or numbers are dropped into their new location, the player might want to delete one or more of the newly placed pieces. Ideally he would select the newly placed piece or pieces, by holding down the ctrl key and clicking his left mouse button and then press the delete key.

Another question: I am using a slide show script to advance the questions on the board. I have to capture and save each new question as a jpg to add questions. Can you recommend a script that would use a text file to enter the list of questions. If I have math symbols like the "not equal" character, will the player be able to see the character on his machine? Is my slide solution the best way to solve this problem?

vwphillips
08-13-2009, 01:24 PM
http://www.vicsjavascripts.org.uk/DragDrop/090813B.htm

Chaim
08-16-2009, 07:55 AM
I worked a long time and finally discovered a bug that was stumping me. When I move a piece to the new location and select it with control and press enter to delete it, it also moves the slide show to the next slide, resetting the whole board :eek:. This is because the enter key is being used for the delete function as well as the next slide function. Could we change the key for the delete function to something else?

vwphillips
08-17-2009, 01:45 PM
how about a right click of the image

or -(minus)

Chaim
08-17-2009, 08:25 PM
Right click sounds great. Thanks

Chaim
08-18-2009, 10:53 AM
What is the code for the right mouse click? What code do I have to replace?

vwphillips
08-18-2009, 11:28 AM
// modified function
function MakeClone(obj){
var e=window.event||arguments.callee.caller.arguments[0];
var clone=obj.cloneNode(true);
document.body.appendChild(clone);
CAry.push(clone);
clone.style.zIndex=zxcLTZ(obj,'z-Index')+1;
// zxcAddEvt(clone,'RemoveClone','click');
clone.oncontextmenu=function(){ this.parentNode.removeChild(this); return false; }
var oop=new zxcDrag(clone,false,'xy',null,DragRemove,null,DragAdd);
oop.down(e);
}

Chaim
08-18-2009, 05:01 PM
Perfect!

Chaim
08-20-2009, 02:02 PM
Found a bug. Everything works well until I use the right mouse click delete function. After deleting and moving an object to a new position the reset function stops working. I put up a test page at: http://koltora.com/mathtest/
Could I bother you to take a look.
P.S. I integrated your slide script for the questions.

vwphillips
08-21-2009, 10:05 AM
function MakeClone(obj){
var e=window.event||arguments.callee.caller.arguments[0];
var clone=obj.cloneNode(true);
document.body.appendChild(clone);
CAry.push(clone);
clone.style.zIndex=zxcLTZ(obj,'z-Index')+1;
// zxcAddEvt(clone,'RemoveClone','click');
clone.oncontextmenu=function(){ this.style.visibility='hidden'; return false; }
var oop=new zxcDrag(clone,false,'xy',null,DragRemove,null,DragAdd);
oop.down(e);
}

Chaim
08-21-2009, 10:23 AM
Wow! That did it. Thanks again

Chaim
08-21-2009, 02:26 PM
Where in the code do I adjust the position of the slide show on the html page? i.e. center or absolute position

vwphillips
08-22-2009, 09:26 AM
It is just a DIV, you could put it im your original table

Chaim
08-22-2009, 10:15 PM
After 26 questions the slide show recycles back to the beginning even though there are 50 questions. Any ideas why. I tried to adjust some of the parameters but could not solve the problem.
Are there other transitions?
Is there a help file I could look at for the slide show?
Thanks again for all your help.

http://www.koltora.com/math/

vwphillips
08-24-2009, 11:40 AM
post a link to the slide show

Chaim
08-24-2009, 01:13 PM
<div id="SlideShow" style="position: absolute; left: 0px; top: 0px; width: 999999px; height: 150px" >
I discovered that increasing the width in the above code gave the room for all the slides.
The slide show is at: http://www.koltora.com/math/
Do you have desolve transitions?
I would like to break the questions into smaller lessons. Is there a better way than creating different pages for each lesson? Could I call different parts of the question group and run the slide show from there? Thanks as always

vwphillips
08-24-2009, 03:11 PM
<style type="text/css">
/*<![CDATA[*/

.parent {
position:relative;overflow:hidden;width:700px;height:150px;border:solid black 0px;text-Align:center;
}
.parent INPUT{
position:relative;top:0px;
}

#SlideShow {
position:absolute;left:0px;top:0px;width:700px;height:150px;
}

.frame {
position:absolute;left:0px;top:0px;width:700px;height:150px;background-Color:#FAFBB;

}

/*]]>*/
</style>

<script src="http://www.koltora.com/math/AnimatorBasic.js" type="text/javascript">
// see http://www.vicsjavascripts.org.uk/AnimatorBasic/AnimatorBasic.htm
</script>

<script type="text/javascript">

function SS(id,cls,ms){
var obj=document.getElementById(id);
var clds=document.getElementById(id).childNodes;
obj.ary=[]
for (var z0=0;z0<clds.length;z0++){
if (clds[z0].className&&clds[z0].className.indexOf(cls)>-1){
obj.ary.push(zxcBAnimator('opacity',clds[z0],50,obj.ary.length>0?0:100,10));
}
}
obj.ary[0].obj.style.zIndex=2
obj.cnt=0;
obj.ms=ms||1000;
}

function UD(id,ud){
var obj=document.getElementById(id);
if (obj.ary){
obj.ary[obj.cnt].obj.style.zIndex=0;
obj.ary[obj.cnt].update([obj.ary[obj.cnt].data[0],0],obj.ms);
obj.cnt+=ud;
obj.cnt=obj.cnt<0?obj.ary.length-1:obj.cnt==obj.ary.length?0:obj.cnt;
obj.ary[obj.cnt].obj.style.zIndex=2
obj.ary[obj.cnt].update([obj.ary[obj.cnt].data[0],100],obj.ms);
Reset();
}
}


function Reset(){
for (var z0=0;z0<CAry.length;z0++){
CAry[z0].parentNode.removeChild(CAry[z0]);
}
CAry=[];
}

</script>

Chaim
08-25-2009, 12:58 PM
Thanks. The fade transition is a little choppy. I think I will stay with your original slide animation.

Chaim
09-03-2009, 06:14 PM
Any idea why the drag sticks on Google Chrome. My latest version is at: http://koltora.com/Chaim_game/html/new.html
The "slide-in" effect was a bit dizzying for the game . I added another Dynamic Drive slide show script into the code. If you have time I would appreciate you look at it. Thanks as always for your very knowledgeable and kind help. Any sugestions would be greatly appreciated.

vwphillips
09-04-2009, 09:25 AM
link gives a 404 error

Chaim
09-05-2009, 10:12 PM
Sorry for the change of location.
This is the link: http://koltora.com/Chaim_game/index.html
Thanks

vwphillips
09-06-2009, 03:54 PM
http://www.vicsjavascripts.org.uk/DragDrop/090906A.htm

Chaim
09-06-2009, 06:23 PM
Works perfect in Chrome now. Thanks once again.

Chaim
09-29-2009, 12:04 AM
Dear Vic,
I am back with another question. I have to make some examples for my game:
http://koltora.com/help/
I put static pieces on the scale but teachers complain that they do not move. Is there a way to place them there and move them away and/or right click the mouse and delete them like the regular cloned items. Thanks for all your help. Chaim

vwphillips
09-29-2009, 09:42 AM
add and position images with class name 'static' where required


<img class="static" src="http://koltora.com/help/image/p_b01.png" style="position:absolute; left:537; top:230" />


add function


function Static(){
var ds=zxcByClassName('static');
for (var oop,z0=0;z0<ds.length;z0++){
oop=new zxcDrag(ds[z0],false,'xy');
CAry.push(ds[z0]);
}
}


change onload to call function Static


onload="Clone('clone');Static();"

Chaim
09-30-2009, 02:03 PM
Many thanks! As usual a great job. Can the image be made deletable. The right click function to delete the clones does not presently work with the static image.

vwphillips
09-30-2009, 04:32 PM
function Static(){
var ds=zxcByClassName('static');
for (var oop,z0=0;z0<ds.length;z0++){
oop=new zxcDrag(ds[z0],false,'xy');
CAry.push(ds[z0]);
ds[z0].oncontextmenu=function(){ this.style.visibility='hidden'; return false; }
}
}

Chaim
10-01-2009, 01:34 AM
:) Can't thank you enough. Everything works beautifully.

Chaim
10-22-2009, 08:48 PM
Hi Vic,
Need your expert help again. I put up a test site at: http://koltora.com/new_game/
It works with FF and IE but not with Chrome or Safari. Any ideas?
Thanks as always,
Chaim

vwphillips
10-23-2009, 05:33 PM
busy at the moment

but your post #43 said that it worked in chome

I will try and get back in the next couple of days

Chaim
10-24-2009, 07:19 PM
Thanks. You are very kind to help. I did some updates since post #43.
No need to solve this issue. A missing tag was at fault. Thanks

vwphillips
10-28-2009, 09:37 AM
the link on post 49 gives 404 error

Chaim
10-28-2009, 07:07 PM
Dear Vic
See post 51. I solved the Chrome and Safari problem by removing a missing tag. Thank you again for all your help and time. I removed the test site. Chaim

Chaim
11-23-2009, 06:56 PM
Hi Vic, Is there anyway that multiple items can be picked and deleted together. The right-click delete function deletes only one item at a time presently. Always appreciative, Chaim

vwphillips
11-24-2009, 10:28 AM
post a link to your latest page

Chaim
11-24-2009, 03:16 PM
http://www.koltora.com/HOE_ver.1.0/

Chaim
11-25-2009, 07:29 AM
Dear Vic,
Just a reminder. The ctrl key already selects multiple objects for drag. Thanks as always.
Chaim

vwphillips
11-25-2009, 11:59 AM
function Init(){
var ds=zxcByClassName('drag')
for (var oop,z0=0;z0<ds.length;z0++){
oop=new zxcDrag(ds[z0],false,'xy',null,DragRemove,null,DragAdd);
}
}

function zxcByClassName(nme,el,tag){
if (typeof(el)=='string') el=document.getElementById(el);
el=el||document;
for (var tag=tag||'*',reg=new RegExp('\\b'+nme+'\\b'),els=el.getElementsByTagName(tag),ary=[],z0=0; z0<els.length;z0++){
if(reg.test(els[z0].className)) ary.push(els[z0]);
}
return ary;
}

var DObjs=[]
var HObjs=[]

function DragAdd(oop,e){
if (e.altKey){
for (var z0=0;z0<HObjs.length;z0++){
if (HObjs[z0]==oop.dobj){
HObjs.splice(z0,1);
oop.dobj.style.border='solid red 0px';
return false;
}
}
oop.dobj.style.border='solid red 1px';
HObjs.push(oop.dobj);
}
else if (e.ctrlKey){
DObjs.push(oop);
oop.drag=false;
oop.dobj.style.border='solid black 1px';
}
else {
for (var z0=0;z0<DObjs.length;z0++){
if (DObjs[z0]!=oop) DObjs[z0].down(e);
}
}
}

function DragRemove(oop,e){
if (!e.ctrlKey){
for (var z0=0;z0<DObjs.length;z0++){
DObjs[z0].dobj.style.borderWidth='0px';
}
DObjs=[];
}
}

function Clone(cls){
var ds=zxcByClassName(cls)
for (var oop,z0=0;z0<ds.length;z0++){
ds[z0].onmousedown=function(){ MakeClone(this); }
}
}

var CAry=[];

// modified function
function MakeClone(obj){
var e=window.event||arguments.callee.caller.arguments[0];
var clone=obj.cloneNode(true);
document.body.appendChild(clone);
CAry.push(clone);
clone.style.zIndex=zxcLTZ(obj,'z-Index')+1;
// zxcAddEvt(clone,'RemoveClone','click');
clone.oncontextmenu=function(){
this.style.visibility='hidden';
for (var z0=0;z0<HObjs.length;z0++){
HObjs[z0].style.visibility='hidden';
}
HAry=[];
return false;
}
var oop=new zxcDrag(clone,false,'xy',null,DragRemove,null,DragAdd);
oop.down(e);
}

function RemoveClone(e){
if (e.ctrlKey){
DeleteObj=this;
}
}

function zxcEventAdd(o,f,e,p) {
if ( o.addEventListener ){ o.addEventListener(e,function(ev){ return o[f](ev,p);}, false); }
else if ( o.attachEvent ){ o.attachEvent('on'+e,function(ev){ return o[f](ev,p); }); }
else {
var prev=o['on'+e];
if (prev){ o['on'+e]=function(ev){ prev(ev); o[f](ev,p); }; }
else { o['on'+e]=o[f]; }
}
}

function zxcAddEvt(obj,fun,ev,p){
if (obj['zxc'+fun+ev]) return;
obj['zxc'+fun+ev]=window[fun];
zxcEventAdd(obj,'zxc'+fun+ev,ev,p);
}

zxcAddEvt(document,'ObjDelete','keypress');


function ObjDelete(e){
var zxckc;
if (e.which){ zxckc=e.which; }
else { zxckc=event.keyCode; }
if (zxckc==13&&DeleteObj){
DeleteObj.parentNode.removeChild(DeleteObj)
}
DeleteObj=null;
}

if (!document.all){ document.captureEvents(Event.KEYDOWN); }



alt click to add to hide list
alt click to remove from hide list

right click to hide all in list

Chaim
11-25-2009, 07:45 PM
Dear Vic,
The new script worked perfectly in Safari and Chrome.
In IE8 the alt select worked properly but I had to double click to delete the selected group.
In Fire Fox 3.5 The alt select turns the object red and begins to drag the object around.
I posted the page with your additional script at:
http://www.koltora.com/HOE_ver.1.0/
I only inserted your new script on the home page.
Thanks again for all your efforts.
Chaim

vwphillips
11-26-2009, 10:05 AM
remove the functions and onload call to Static();

vwphillips
12-14-2009, 12:31 PM
Is there a way to assign keyboard keys to the dragable items under the blackboard

I have no idea what the objective is

vwphillips
12-14-2009, 03:21 PM
this thread is titled

Drag multiple images

You should start another tread with a suitable title and task definition.