我已经开发了一个Javascript程序(下面的代码),以拖放一些包含(希腊语)字符并包含在简单的<span>
元素中的<div>
元素。
第一次正确显示页面;所有字符都是aligned verticalally >>。
我可以增大或减小Window的高度或宽度,并且所有角色继续垂直对齐。
我可以使用标准<div>
新JavaScript API在drag and drop
中移动字符。
但是出了点问题。垂直对齐方式开始丢失!
移动10个或更多之后,我看到以下结果
通常,blue-vertical
条不可见,但在某些情况下会突然出现。不是错误,仅是我现在用来解释会发生什么的特征。
我在Opera
,Chrome
,Edge Chromium
和Firefox
的最新版本(2020)上具有相同的结果。
[在Firefox上,当我检查元素时,在space-text
中的所有<span>
之间显示一个<div>
区域。每次移动后,将删除掉落在space-text
和<span>
目标(已拖放可拖动<span>
的<span>
)之间的<span>
区域!
在Firefox上可见的space-text
区域似乎与Chrome上显示的blue-vertical
条相对应。
如果这不是浏览器的错误,在移动一些<span>
元素(1个或更多)后,我该怎么做才能保持<span>
的原始垂直对齐?
以下使用的JavaScript代码
$(document).ready(function() { $('.unicode').attr('draggable', 'True'); $('.unicode').bind( { dragstart: function(ev) { eDraggable = ev.target; } , dragenter: function(ev) { ev.preventDefault(); // needed for IE ev.target.style.color = 'red'; } , dragover: function(ev) { ev.preventDefault(); // needed for IE } , dragleave: function(ev) { ev.target.style.color = 'black'; } , drop: function(ev) { ev.target.style.color = 'orange'; ev.target.parentNode.insertBefore(eDraggable, ev.target.nextSibling); } }); });
.unicode { font-size: 32px; cursor: pointer; min-width: 60px; padding: 2px; display: inline-block; text-align: center; } .unicode:hover { background-color: yellow; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div> <span class='unicode'>α</span> <span class='unicode'>β</span> <span class='unicode'>γ</span> <span class='unicode'>δ</span> <span class='unicode'>ε</span> <span class='unicode'>ζ</span> <span class='unicode'>η</span> <span class='unicode'>θ</span> <span class='unicode'>ι</span> <span class='unicode'>κ</span> <span class='unicode'>λ</span> <span class='unicode'>μ</span> <span class='unicode'>ν</span> <span class='unicode'>ξ</span> <span class='unicode'>ο</span> <span class='unicode'>π</span> <span class='unicode'>ρ</span> <span class='unicode'>ς</span> <span class='unicode'>σ</span> <span class='unicode'>τ</span> <span class='unicode'>υ</span> <span class='unicode'>φ</span> <span class='unicode'>χ</span> <span class='unicode'>ψ</span> <span class='unicode'>ω</span> <span class='unicode'>Α</span> <span class='unicode'>Β</span> <span class='unicode'>Γ</span> <span class='unicode'>Δ</span> <span class='unicode'>Ε</span> <span class='unicode'>Ζ</span> <span class='unicode'>Η</span> <span class='unicode'>Θ</span> <span class='unicode'>Ι</span> <span class='unicode'>Κ</span> <span class='unicode'>Λ</span> <span class='unicode'>Μ</span> <span class='unicode'>Ν</span> <span class='unicode'>Ξ</span> <span class='unicode'>Ο</span> <span class='unicode'>Π</span> <span class='unicode'>Ρ</span> <span class='unicode'>Σ</span> <span class='unicode'>Τ</span> <span class='unicode'>Υ</span> <span class='unicode'>Φ</span> <span class='unicode'>Χ</span> <span class='unicode'>Ψ</span> <span class='unicode'>Ω</span> </div>
[在最后一分钟,我已更改掉的字体颜色为<span>
,以便于分析问题。您可以看到,只有所有行中没有掉落的<span>
(所有字符均为黑色)的所有字符仍继续垂直对齐。
我还用一个简单的'X'字符替换了Unicode,以确保此问题与Unicode无关。
我已经开发了一个Javascript程序(下面的代码)来拖放一些包含(希腊)字符的元素,并包含在简单的
首先,它不是错误,但是要理解它非常棘手。
每个Unicode
字符包含在<span>
中。为了在Notepad ++上读取HTML文件,我生成了一个文件,其中每个<span>
都位于这样的一行上