jQuery-UI:sortable() 占位符感觉很粘
jQuery-UI: sortable() placeholder feel sticky
我正在尝试使用$.sortable
来实现一个简单的难题:
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<style>
span {
display: inline-block;
width: 1em;
text-align: center;
border: 1px solid;
background: white;
margin: 0 4px;
}
.vowel { color: red }
.vowel:hover {
cursor: pointer;
background: red;
color: white;
}
.word { padding: 5px }
#words, #vowels{
float: left;
clear: both;
padding: 5px;
margin: 5px;
}
#words { border: 1px solid black }
#vowels { border: 2px solid red }
#vowels .placeholder {
display: none;
}
.word .placeholder {
width: 4px;
margin: -2px;
background: pink;
height: 1em;
border: none;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<script>
$(function(){
$('#vowels,.word').disableSelection().sortable({
cursor: 'pointer',
placeholder: 'placeholder',
cancel: '.consonant',
connectWith: '#vowels,.word',
helper: 'clone',
appendTo: 'body',
stop: function(event, ui) {
var $uiItem = $(ui.item);
if ($uiItem.parent().is('#vowels')) $uiItem.remove();
}
});
$('#vowels').bind('sortstart', function(event, ui){
var $uiItem = $(ui.item);
$uiItem.clone().show().insertBefore($uiItem);
});
});
</script>
</head>
<body>
<div id="vowels">
<span class="vowel">A</span>
<span class="vowel">E</span>
<span class="vowel">I</span>
<span class="vowel">O</span>
<span class="vowel">U</span>
<span class="vowel">Y</span>
</div>
<div id="words">
<div class="word">
<span class="consonant">H</span>
<span class="consonant">P</span>
<span class="consonant">P</span>
</div>
<div class="word">
<span class="consonant">B</span>
<span class="consonant">S</span>
<span class="consonant">H</span>
<span class="consonant">F</span>
<span class="consonant">L</span>
</div>
<div class="word">
<span class="consonant">D</span>
<span class="consonant">C</span>
</div>
<div class="word">
<span class="consonant">G</span>
<span class="consonant">R</span>
<span class="consonant">M</span>
<span class="consonant">P</span>
</div>
<div class="word">
<span class="consonant">D</span>
<span class="consonant">P</span>
</div>
<div class="word">
<span class="consonant">S</span>
<span class="consonant">N</span>
<span class="consonant">Z</span>
</div>
<div class="word">
<span class="consonant">S</span>
<span class="consonant">L</span>
<span class="consonant">P</span>
</div>
</div>
</body>
</html>
虽然它有效,但它并没有像我希望的那样好。 我可以拖拽字母,但牌卒并不像我希望的那样平稳移动,偶尔会粘在某个位置。
我能做些什么来让它更平稳地移动吗?
您可能遇到的一个问题与jQuery UI错误#4759有关。你可以在这里阅读。从本质上讲,问题在于选项connectWith 在初始化期间比初始化后慢得多。所以你需要做的就是像这样移动连接:
$(function() {
$('#vowels,.word').disableSelection().sortable({
cursor: 'pointer',
placeholder: 'placeholder',
cancel: '.consonant',
helper: 'clone',
appendTo: 'body',
stop: function(event, ui) {
var $uiItem = $(ui.item);
if ($uiItem.parent().is('#vowels')) $uiItem.remove();
}
}).sortable(
"option", "connectWith", '#vowels,.word'
);
$('#vowels').bind('sortstart', function(event, ui) {
var $uiItem = $(ui.item);
$uiItem.clone().show().insertBefore($uiItem);
});
这是jsFiddle。
相关文章:
- 使用javascript的Asp.net内容占位符
- Internet Explorer缺少占位符支持,特别是密码字段
- 如何隐藏按钮单击事件上的占位符
- 需要URL模板占位符查找和替换功能的输入
- 初始化ng模型时,Angular ui选择占位符不起作用
- 如何在ie7或更高版本中设置密码字段的占位符
- 在不使用javascript的情况下,可以在表单字段中设置文本占位符(以提示最终用户插入特定格式)
- Select2-使用自定义模板时不显示占位符
- 替换字符串中的占位符值
- 为什么我应该使用HTML5(上下文:占位符)
- 在contentEditable元素中居中占位符插入符号
- 从气球弹出窗口中删除占位符
- 选择“选项”时更改输入的占位符
- 错误:ReCAPTCHA占位符元素必须为空
- 如何更改文本区域的颜色's文本,具体取决于它是否为占位符
- 得到一个没有属性的错误“;占位符”;在xhtml strict 1.0中
- 使用Node/Javascript提取字符串中的所有占位符
- 更改 html 输入字段中的占位符属性
- 当用户在输入字段事件中输入内容时,为该字段事件添加动画占位符
- jQuery-UI:sortable() 占位符感觉很粘