Closed mekkolodziejski closed 5 years ago
Hi @szybki8562, thank you for the comment.
Yes of course you can change options including the snap
dynamically.
can u help me how ? im new in js THX
For example: https://jsfiddle.net/yjmhdr2a/
thanks for the answer, but it was not what I was talking about
I have random id elements added while the application is running. I asked if it can be added to the current snap or from whole array svg
I will show you a piece of code that I tried. maybe it will be easier for you to understand me
for (var it in ARRAY) { TEMPARRAY.push('document.getElementById("' + ARRAY[it].id + '")'); } draggable.snap = { targets: TEMPARRAY, gravity: 20, edge: 'outside', };
or +=
It seems that the example is what you want. You can specify snap targets even if those have random IDs. See line 4.
i cant write this way
draggable.snap = [ **_document.getElementById('box-a'), document.getElementById('box-b')_** ];
i dont have this elements at start and i dont know what will the id elements that I want to attract, adds to the array with time
if he puts this code in the loop, the appeal is only in the last element
I merged the example and your code:
https://jsfiddle.net/yjmhdr2a/1/
BTW, the TEMPARRAY
and gravity
option are not needed.
Optimized: https://jsfiddle.net/yjmhdr2a/2/
`ARRAY = [{id: 'box-a'}, {id: 'box-b'}];
var TEMPARRAY = ARRAY.map(function(target) { return document.getElementById(target.id);});
alert(TEMPARRAY);`
in my proj alert is null in jsfiddle OK
Sorry, my English is poor. What do you mean?
TEMPARRAY have empty
Did you try this? https://jsfiddle.net/yjmhdr2a/2/
ARRAY.map propably this not working
something is wrong with my project your fiddle is OK
THX for yr time
The null
is different from "empty".
You should clear up that.
If that is "empty", the getElementById
couldn't get elements.
If that is null
, your code has problem.
i have comma
in jsfiddle
[object HTMLSpanElement],[object HTMLSpanElement]
same code add at start
` ARRAY = [{ id: 'box-a' }, { id: 'box-b' }];
for (var j in ARRAY) {
alert(ARRAY[j].id); <<<<----->>>> HERE IS OK I HAVE VALUES
}
var a = ARRAY.map(function (target) { return document.getElementById(target.id) });
alert(a); <<<<----->>>> HERE IS ONLY COMMA
`
For example:
var ARRAY = [{id: 'box-a'}, {id: 'box-b'}],
TEMPARRAY = ARRAY.map(function(target) { return document.getElementById(target.id); });
This code gets elements box-a
and box-b
.
In other words, that gets nothing if there are not box-a
and box-b
.
What is "comma"?
,
I know "comma". What do you mean "i have comma"?
array.map return only comma without values in alert before map is ok have values
Please don't change comments that were read because we can't have conversation. So, could you explain the current progress?
I have no value after the array map
What do you mean "no value"?
Try this:
console.log(ARRAY);
`ARRAY = [{id: 'box-a'}, {id: 'box-b'}];
var a = ARRAY.map(function(target) { return document.getElementById(target.id)});
alert(a); <<<--->>> jsfiddle = [object HTMLSpanElement],[object HTMLSpanElement] my proj = , ` console same values
debugger no error
In console, try this:
document.getElementById('box-a')
array map needs some library?
What is your environment? browser and version?
vs code jquery 3.3.1 opera
Which version of Opera?
pure html with same result
opera new chrome and firefox developer same result
opera 56.0.3051.36
I see. The Array#map
in your environment doesn't need a library because ECMAScript 5 supports that.
So, did you that? https://github.com/anseki/plain-draggable/issues/11#issuecomment-429697715
where?
Try this in console of browser: https://github.com/anseki/plain-draggable/issues/11#issuecomment-429697715
var numbers = [4, 9, 16, 25]; alert(numbers.map(Math.sqrt));
this map ok
Yes, of course I know. So, did you try the code that I indicated?
document.getElementById('box-a') ?
Yes.
i dont know how in console this 'document.getElementById('box-a')' must be a return of one value
`ARRAY.map(function(target) { alert(target.id); OK });
ARRAY.map(function(target) { alert(document.getElementById(target.id)); NO OK }); `
Sorry, my English is poor. Do you mean that you don't know how to execute the code in console?
return null
?
i dont have that element i only check array draggable working
Do you mean that this code returned null
?
document.getElementById('box-a')
yes i dont have element with box-a id
ok i understand im very sleepy sorry for my bad
i got null or nothing because i wanted getelement
Hello There is a possibility to add array items or dynamically (multiple) to snap targets?