- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为明信片编写一个构造函数。在此构造函数上,我必须能够添加文本和输入以编辑这些文本。而且这些文本是可拖动的。我有将文本和输入附加到正确位置的功能:
function addTextWithControls(maxId, posX, posY, text, fontstyles) {
var idForAdding = parseInt(maxId);
idForAdding++; //get id for appending elements
$('#inputsBox').append('<div class="inputBox"><input type="text" name="text'+idForAdding+'" id="text'+idForAdding+'Inp" placeholder="Введите текст" value="'+text+'" onkeyup="changeText('+idForAdding+');" data-type="textInput" data-id="'+idForAdding+'"/><span id="text'+idForAdding+'Remover" data-type="remover" class="textRemover" data-id="'+idForAdding+'"></span><div class="cleaner"></div></div>');
$('div.finishedPic').append('<span id="text'+idForAdding+'Span" data-type="textOnPic" style="left: '+posX+'px; top:'+posY+'px; '+fontstyles+'" data-id="'+idForAdding+'">'+text+'</span>');
$(function() {
//calling .draggable for new appended element
$( "div.finishedPic span" ).draggable({ containment: "parent" ,
drag: function(){
console.log('.');
},
});
//calling .sortable for new appended element
$( "#inputsBox" ).sortable({
placeholder: "ui-state-highlight",
update: function(){
setZindexes();
}
});
$( "#inputsBox" ).disableSelection();
});
}
我有两种方法来调用这个 addTextWithControls() 函数:第一种方式:加载文档时我调用 initCard() 函数:
$(document).ready(function(){
initCard();
});
因此 initCard() 函数包含 addTextWithControls() 函数:
function initCard(json) {
$('div.finishedPic img').attr('src', json.image); //set background image
$.each(json.texts, function() { //parse json for getting information
var styles = '';
var obj = this.fontstyles;
forEach(obj, function(key, value){
styles += key+': '+value+'; '; //get string with text styles. String looks like: 'font-size: 12px; color: #fff000;'
})
addTextWithControls(this.id, this.posX, this.posY, this.text, styles);
});
输入名称为“json”的数据,它是有关文本图层的信息。字体大小、颜色、字体样式等。这个变体正在运行!
但是如果想通过这种方式调用相同的函数addTextWithControls():
$(document).ready(function(){
$('#addText').on('click', function(){
var id = getMaxTextId(); //get max id before appending
addTextWithControls(id, '320', '120', 'Test sample', 'font-size: 25px; color: red;');
});
});
文本和输入已追加,但出现错误:
Uncaught TypeError: Object #
<Object>
has no method 'draggable'
链接到(此信息来自控制台。我无法添加图片,因为没有足够的声誉):
$(function() {
$( "div.finishedPic span" ).draggable({ containment: "parent" ,
Uncaught TypeError: Object #<Object> has no method 'draggable'
drag: function(){
console.log('.');
},
});
并且可拖动不起作用。所以主要问题是:为什么两个不同地方调用的同一个函数 addTextWithControls() 表现不同。请帮助我,因为我的大脑正在融化。
最佳答案
看起来您还没有包含 jQuery UI 脚本。
您可以将这些添加到您的 html 中:
<script src="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"</script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
或者,也许您在脚本之后添加了它。
关于javascript - 对象 #<Object> 没有方法 'draggable',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22526030/
更新: See latest updates at the bottom. 原装 我有 flutter Draggable 和 DragTarget 小部件,它们正在工作,但在放置 DragTarge
我有下面的板。有一个覆盖( Stack )的 2 x 10 小部件,一些透明的小部件是 DragTargets在它们之上,相同的宽度和高度有 Draggable . Draggable那些是包含图像的
当前输出 预期输出 正如我们在第一张图片中看到的,可拖动的 ul li 位于可放置区域的右侧。 当我从数据库中获取内容时,我将在可拖动的 ul 中拥有 n 个元素。 但是当我尝试将 height :
对 jquery 有点陌生,我正在使用可拖动和可放置的东西。我有两个可拖动对象和一个可放置对象。我不太清楚如何让它根据我放置的盒子做不同的事情。这是我的 jquery: $(funct
我在拖动列表中有一个项目池,它使用 connectToSortable 选项连接到一个可排序对象。现在我想从这个排序列表中删除一些项目并将它们移回拖动列表。有点像撤消。假设用户将大约 5 个项目移动到
当使用 jQuery UI draggable+sortable 时,draggable 元素在放入 sortable 时会丢失它的 css。这是我的代码,这是一个 js fiddle demo 尝试
我正在使用 jQuery 构建一个座位应用程序。我的 table 周围有椅子,可能有客人坐在椅子上。每个表格都有一个可拖动的包装 div。 table 里面有任意数量的椅子分区。客人可以在任何椅子座位
这是我从 http://jqueryui.com/demos/draggable/ 中获取的代码 jQuery UI Draggable - Default functionalit
我在使用 Vue.js 和 VueDraggable 库时遇到问题 ( https://github.com/SortableJS/Vue.Draggable )这是一个代码示例:
我使用 jQuery UI 制作了一个可拖动对象,并将帮助器选项设置为“克隆”。如果我开始拖动元素,则会创建克隆,并且它会按预期工作,此外,初始元素中应用的类不会传递给克隆。如果我改为使用辅助选项的函
根据 jQuery UI 文档,将 addClasses 选项设置为 false“将阻止将 ui-draggable 类添加到”可拖动元素: http://api.jqueryui.com/dragg
使用 jQuery Draggable 如何限制可拖动对象被拖动 仅在一个方向 ? 即当 axis: 'y' 时只有顶部或只有底部 并且只有在 axis: 'x' 时才向左或仅向右 这意味着如果我想要
我试图包含我的可拖动元素,这样它就不能被拖动到可查看窗口之外,如果用户位于页面顶部,这种方法效果很好,但是如果你向下滚动,那么它就会把一切搞乱. 我该怎么做? $(".chat-wrapper > l
我有几个draggable & droppable我页面上的元素,它们具有 accept 属性。 目前我的代码设置如下: $(".answer." + answer).draggable({
我正在做一个小项目,并且使用 jquery 的 draggable 有一个有趣的遏制问题。 : 基本上,我有两个 div - 顶部和底部。然后,我有第三个 div,它是 .draggable({}),
如何防止用户将元素拖到窗口之外? elm.css({ top : $(window).scrollTop() + ($(window).height() - elm.height())
我有一个问题需要你帮我解决。我有两个这样的列表。 itemA itemB Add Item itemC Add Item 这里的问题是当我将 itemC 拖动到
我有一个 jQuery Draggable() 函数,并且在拖动时基于 if 执行几个其他函数。像这样的事情: $("div.element").draggable({ drag: funct
我有一个可拖动的 div。现在,我希望该 div 粘在浏览器窗口的边框上。这可能吗?或者也许有一些扩展插件可以实现这一点? 最佳答案 由于我无法模仿 jsfiddle 框架中的 window,因此我将
背景 我正在构建一个 meteor 应用程序,在其中保存相应 div 的对象位置和大小。当再次访问此页面时,我重新创建所有 div 并适本地重新填充对象大小和位置。我正在重新填充 div 和相应的对象
我是一名优秀的程序员,十分优秀!