Droppable in Famous.js?

天大地大妈咪最大 提交于 2019-11-30 22:31:32

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