首页 \ 问答 \ HTML5拖放(HTML5 Drag and Drop)

HTML5拖放(HTML5 Drag and Drop)

我一直在想办法在网页上制作拖放区域。 我有多个可调整大小的<div> ,我希望能够将这些拖动到任何位置。 想想它就像在桌面上拖动桌面图标并将其放置在任何地方。 如果我可以向这些<div>添加按钮来更改它们的z索引并使它们重叠,那将会很好。 这需要使用<canvas>吗? 我目前使用<section>作为拖动区域。

谢谢!


I've been having trouble coming up with a way of making a drag and drop area on a web page. I have multiple resizable <div>s, and I want to be able to drag these anywhere. Think of it like dragging desktop icons around the desktop and placing them anywhere. It would be nice if I could add buttons to these <div>s to change their z-indexes and have them overlap. Would this require use of <canvas>? I am currently using <section> for the drag area.

Thanks!


原文:https://stackoverflow.com/questions/6090295
更新时间:2022-09-02 19:09

最满意答案

这是一个可扩展且安全的解决方案:

const languages = {
  en: 'en',
  pt: 'pt',
  es: 'es'
};

type Language = $Keys<typeof languages>;

const languageMap: { [key: string]: ?Language } = languages;

function updateLanguage(lang: Language) {
    // do nothing
}

type SelectOption = {
    value: string
};
const selectedOption: SelectOption = {value: 'en'};

if(languageMap[selectedOption.value]) {
  updateLanguage(languageMap[selectedOption.value]);
}

Here is a scalable and safe solution:

const languages = {
  en: 'en',
  pt: 'pt',
  es: 'es'
};

type Language = $Keys<typeof languages>;

const languageMap: { [key: string]: ?Language } = languages;

function updateLanguage(lang: Language) {
    // do nothing
}

type SelectOption = {
    value: string
};
const selectedOption: SelectOption = {value: 'en'};

if(languageMap[selectedOption.value]) {
  updateLanguage(languageMap[selectedOption.value]);
}

相关问答

更多
  • 没有理由将enum值转换为字符串/从字符串转换。 只需保存并将其作为int读回。 但对原始问题的简短回答是: NSStringEncoding encoding = [encodingValueAsString intValue]; 等待 - 因为您将字符串保存为十六进制值,所以不起作用。 您需要使用NSScanner : NSScanner *scanner = [NSScanner scannerWithString:encodingValueAsString]; NSStringEncoding e ...
  • 这是一个可扩展且安全的解决方案: const languages = { en: 'en', pt: 'pt', es: 'es' }; type Language = $Keys; const languageMap: { [key: string]: ?Language } = languages; function updateLanguage(lang: Language) { // do nothing } type SelectOp ...
  • 从v0.32.0开始,Flow不会抱怨无法访问的代码,除非它是类似的 // @flow function foo() { throw new Error(); return 123; // This will error }. 但是,请考虑以下代码 // @flow function foo(x: string): Object { if (x === 123) { return x; } return {}; } 目前这个代码不会出错。 Flow实际上注意到x === 1 ...
  • 是的,您可以使用.ToString()获取枚举的字符串值,但是您不能在switch语句中使用.ToString() 。 Switch语句需要常量表达式,而.ToString()不会在运行时进行求值,因此编译器会抛出错误。 为了获得所需的行为,通过稍微改变方法,您可以使用enum.Parse()将action字符串转换为枚举值,并改为使用该枚举值。 从.NET 4开始,您可以使用Enum.TryParse() ,并在前期执行错误检查和处理,而不是在交换机主体中。 如果是我,我会将字符串解析为枚举值,并打开它, ...
  • 您可以使用简单的转换将int转换回枚举成员,然后调用ToString() : int value = GetValueFromDb(); EnumDisplayStatus enumDisplayStatus = (EnumDisplayStatus)value; string stringValue = enumDisplayStatus.ToString(); You can convert the int back to an enumeration member with a simple cas ...
  • 你不行 我想你有四个选择。 所有四个都提供了一个解决方案,但是有一个稍微不同 选项一: 在枚举上使用内置的name() String name = Modes.mode1.name(); // Returns the name of this enum constant, exactly as declared in its enum declaration. 选项二: 如果你想要更多的控制,添加覆盖属性到你的枚举 public enum Modes { mode1 ("Fancy Mod ...
  • 是的, Blah.valueOf("A")会给你Blah.A 静态方法valueOf()和values()在编译时创建,不会出现在源代码中。 他们确实出现在Javadoc; 例如, Dialog.ModalityType显示两种方法。 Yes, Blah.valueOf("A") will give you Blah.A. Note that the name must be an exact match, including case: Blah.valueOf("a") and Blah.valueOf ...
  • 在某种程度上,你将不得不迭代你所有的枚举集合,并且必须通过映射结构(初始群体)或基本循环来比较它们。 用一个基本的循环来完成是相当容易的 ,所以我没有看到你不想走这条路的任何理由。 下面的代码片段假定该字段名为friendlyTask 。 public static ServerTask forTaskName(String friendlyTask) { for (ServerTask serverTask : ServerTask.values()) { if(serverTas ...
  • function EnumFromString(const str: string): TJOBTYPEENUM; begin for Result := low(Result) to high(Result) do if JOBTYPEStrings[Result]=str then exit; raise Exception.CreateFmt('Enum %s not found', [str]); end; 在真实的代码中,你想使用自己的异常类。 如果您想允许不区分大 ...
  • “ToString-like”函数实现有两种选择: 实现一个简单的静态开关案例功能。 码: std::string ThingEnumToString(ThingEnum thing) { switch (thing) { case Thing1: return std::string("Thing1"); case Thing2: return std::string("Thing2"); case Thing3: r ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。