Droppable in Famous.js?

家住魔仙堡 提交于 2019-11-30 17:33:59

问题


I am trying to implement a draggable/dropable image in famous.js. That is, if an image is dropped on the correct surface, an event will trigger.

On my draggable image, I am listening for the 'touchend' event. No problem here.

I also have a touchend event connected to my 'target' surface. The problem is that this touchend event doesn't fire when I release the draggable, only the touchend from the draggable is triggered.

My question is: Does Famous.js have a 'droppable' object like in jQuery? If not, how can I detect when an event occurs on top of my target view?

My code is pretty much just the code from this answer, with some event handlers added on.


回答1:


There is no droppable object yet.. but you can use normal HTML5 DOM events on your surfaces. Here is a working drag and drop example that logs the files that you dropped.

var Engine = require('famous/core/Engine');
var Surface = require('famous/core/Surface');
var Modifier = require('famous/core/Modifier');

var context = Engine.createContext();

var surface = new Surface({
    size:[200,200],
    content:"Drop Here!",
    properties:{
        border:'4px solid white',
        backgroundColor:'green',
        fontSize:'36px',
        fontFamily:'arial',
        textAlign:'center',
        color:'white',
        lineHeight:'200px'
    }
});

surface.on('dragenter', function(evt){
    evt.preventDefault();
    return false;
});

surface.on('dragleave', function(evt){
    surface.setProperties({border:'4px solid white'});
    evt.preventDefault();
    return false;
});

surface.on('dragover', function(evt){
    surface.setProperties({border:'4px solid black'})
    evt.preventDefault();
    return false;
});

surface.on('drop', function(evt){

    evt.preventDefault();
    evt.stopPropagation();

    surface.setProperties({border:'4px solid white'});

    files = evt.dataTransfer.files;
    console.log(files);
});

context.add(new Modifier({origin:[0.5,0.5]})).add(surface);


来源:https://stackoverflow.com/questions/24614367/droppable-in-famous-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!