Comments (6)
I use only native, standard HTML5 DnD implementation in this project, so you can use only Image or Canvas elements to show the drag operation. Please follow the resources below to get more information about DataTransfer.setDragImage method:
- https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/setDragImage
- https://html.spec.whatwg.org/multipage/interaction.html#dom-datatransfer-setdragimage
The getDragImage is an ordinary name of any function you can use by you own. You can change this name to any other.
The argument of getDragImage method is just a value you can pass through from the markup. You can drop it and call getDragImage without any arguments.
from ng2-dnd.
So, I think all right. Only one notice. I think that mention about custom [dragImage] should be placed in MD file. You can also suggest users about using HTML to SVG technique (via svg with foreignObject, then creating Blob with type 'image/svg+xml', then creating window.URL.createObjectUrl from the Blob and then insert this into some image element. Now you can use this image which linked to some peace of html in custom dragImage). Thank you!
from ng2-dnd.
You can create new instance of DragDropConfig class:
bootstrap(App, [
...,
DND_PROVIDERS // It is required to have 1 unique instance of your service
provide(DragDropConfig, {useFactory: () => {
return () => {
let cfg = new DragDropConfig();
// Create an image
let img = new Image();
// Use your image here
img.src = 'http://your-site.org/images/simpler.png';
// You can specify offset by x and y coordinate as second and third parameters
img.dragImage = new DragImage(img);
return cfg;
}
}})
]).catch(err => console.error(err));
Is that solution acceptable for you?
from ng2-dnd.
Thank you. I found that this code snippet works:
bootstrap(App, [ ..., DND_PROVIDERS, provide(DragDropConfig, {useFactory: () => { let cfg = new DragDropConfig(); // Create an image let img = new Image(); // Use your image here img.src = 'http://your-site.org/images/simpler.png'; // You can specify offset by x and y coordinate as second and third parameters cfg.dragImage = new DragImage(img); return cfg; }}) ]).catch(err => console.error(err));
But it seems overriding in all cases. In the constructor of DragDropConfig I can't parse some control value (for example, maybe class of dragged element or another value to detect that should we change common behavior of cloning copy of dragged element to another strategy).
For example, there are dragged element classes. If the classList contains 'drag-ico-cogs' class, so, I want to override default behavior of cloning and set something like this:
let el = document.createElement('i'); el.classList = 'fa fa-cogs'; cfg.dragImage = new DragImage(el);
Is it possible to get some information about dragging process in construction of DragDropConfig?
I tried to extend AbstractComponent and override ondragstart function, but there are some restrictions (for example, _onDragStart is private, but it will be cool, if it would be protected).
from ng2-dnd.
I propose to add the property dragImage to the Draggable component, so you can use:
- The string value as url to the image
<div class="panel panel-default"
dnd-draggable [dragEnabled]="true"
[dragImage]="/images/simpler.png">
...
- The custom function to return the value of dragImage programmatically:
<div class="panel panel-default"
dnd-draggable [dragEnabled]="true"
[dragImage]="getDragImage(someData)">
...
getDragImage(value:any): string {
return value ? "/images/simpler1.png" : "/images/simpler2.png"
}
What do you think?
from ng2-dnd.
It would be great, but I think about more flexible property like dom-element. For example, I don't use any images on my productions, but use some reusable UI elements and icons (for instance, font-awesome). And for my case I need some html in dragImage, for example, . Maybe I don't understand clearly about DataTransfer.setDragImage(). Is it possible to use some custom html?
And I can't understand what about a value - argument of getDragImage() function? Will it represent the dragging element? What the question. I will need specify some type (which cause different images when dragging) in class of dom-element or in object of dragData?
Thanks!
from ng2-dnd.
Related Issues (20)
- make the abstract item disappeared
- Drop outside dropzone does not fire any event
- Add allowFileDrop functionality to dnd-sortable-container HOT 1
- Drop is dropping into multiple targets
- Is this project still maintained? HOT 3
- cannot install thru npm HOT 1
- Not Support Angular 7 HOT 9
- Update to angular 7 HOT 3
- Horizontal sortable not working properly if list items have dynamic width
- Gets in a loop when there is a larger number of items(not so large..)
- How to change cursor position while dragging item
- Inputs lost focus in a dynamic list IE11
- How can i get the START index when i drag and drop and item inside the same list
- Is there a way to add a placeholder when user drops? HOT 1
- angular 8 support? HOT 4
- Multi list sortable between containers not working in IE
- Multi list sortable
- ng2-dnd not working with angular10 HOT 19
- README broken (Credits/License)
- No changelog
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ng2-dnd.