android連續(xù)拖動導(dǎo)致掛起的解決方法
當(dāng)我保持對連續(xù)將對象拖有時在移動后 5 6 拖/滴,看到有時不獲取對象還原不回來,我不能用于以后。
基本上我有對兩個對象組的 canvas 在 time 可以有最大的兩個圖像不是更多比,也看到圖像
為什么會發(fā)生呢,我們?nèi)绾畏乐梗?/p>
(function () {
var canvas = new fabric.Canvas('canvas');
var canvas_el = document.getElementById('canvas');
var canvas1 = new fabric.Canvas('canvas1');
var group;
fabric.Image.fromURL('img/blank.png', function (img) {
var img1 = img.set({
left: 0,
top: 0
});
fabric.Image.fromURL('img/blank.png', function (img) {
var img2 = img.set({
left: 0,
top: 0
});
group = new fabric.Group([img1, img2], {
left: 0,
top: 0
});
canvas.add(group)
});
});
fabric.Image.fromURL('img/blank.png', function (img) {
var img1 = img.set({
left: 0,
top: 0
});
fabric.Image.fromURL('img/blank.png', function (img) {
var img2 = img.set({
left: 0,
top: 0
});
group1 = new fabric.Group([img1, img2], {
left: 0,
top: 0
});
canvas1.add(group1)
});
});
$(document).ready(function () {
/* Define drag and drop zones */
var $drop = $('#canvas-drop-area,#canvas-drop-area1'),
$gallery = $('td > #image-list li'),
$draggedImage=null;
/* Define the draggable properties */
$gallery.draggable({
helper: 'clone',
start: function (e) {
$draggedImage=event.target;
$drop.css({
'display': 'block'
})
},
stop: function () {
$(this).find('img').css({
/* 'opacity': 0.4 */
});
$drop.css({
'display': 'none'
});
$draggedImage=null;
},
revert: true
});
/* Define the events for droppable properties */
$drop.droppable({
over: function (event, ui) {
$(this).addClass('active');
},
drop: function (event, ui) {
var image =$draggedImage&& $draggedImage.src;
console.log($draggedImage.alt);
img_to_canvas(image,$draggedImage.alt,$(event.target).is("#canvas-drop-area")?1:2);
},
out: function (event, ui) {
$(this).removeClass('active');
},
deactivate: function (event, ui) {
$(this).removeClass('active');
}
});
});
var img_to_canvas = function(image,sendfront,checkcanvas) {
var img = new Image();
img.src = image;
if(checkcanvas =='1'){
if(sendfront=='top'){
fabric.util.loadImage(img.src, function (img) {
group.item(0).setElement(img);
canvas.renderAll();
});
}else{
fabric.util.loadImage(img.src, function (img) {
group.item(1).setElement(img);
canvas.renderAll();
});
}
canvas.calcOffset();
}else{
if(sendfront=='top'){
fabric.util.loadImage(img.src, function (img) {
group1.item(0).setElement(img);
canvas1.renderAll();
});
}else{
fabric.util.loadImage(img.src, function (img) {
group1.item(1).setElement(img);
canvas1.renderAll();
});
}
canvas1.calcOffset();
}
}
})();
解決方法
更改
$drop.droppable({
over: function (event, ui) {
$(this).addClass('active');
},
drop: function (event, ui) {
var image =$draggedImage&& $draggedImage.src;
為
$drop.droppable({
over: function(event, ui) {
$(this).addClass('active');
},
drop: function(event, ui) {
$draggedImage = ui.draggable.find("img").get(0);
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。
- Android使用WindowManager構(gòu)造懸浮view
- 通過案例分析Android WindowManager解析與騙取QQ密碼的過程
- Android自定義View實(shí)現(xiàn)拖動選擇按鈕
- Android 可拖動的seekbar自定義進(jìn)度值
- Android編程之控件可拖動的實(shí)現(xiàn)方法
- Android編程實(shí)現(xiàn)圖標(biāo)拖動效果的方法
- Android編程實(shí)現(xiàn)圖片的瀏覽、縮放、拖動和自動居中效果
- 在android中實(shí)現(xiàn)類似uc和墨跡天氣的左右拖動效果
- android 添加隨意拖動的桌面懸浮窗口
- Android使用WindowManager制作一個可拖動的控件
相關(guān)文章
ImageView點(diǎn)擊可變暗的實(shí)例代碼(android代碼技巧)
本文給大家分享一段實(shí)例代碼給大家介紹ImageView點(diǎn)擊可變暗的實(shí)例代碼,非常不錯,具有參考借鑒價(jià)值,需要的的朋友參考下吧2017-02-02
Android實(shí)現(xiàn)多線程下載圖片的方法
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)多線程下載圖片的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09
View觸發(fā)機(jī)制API實(shí)現(xiàn)GestureDetector OverScroller詳解
這篇文章主要為大家介紹了View觸發(fā)機(jī)制API實(shí)現(xiàn)GestureDetector OverScroller詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11
Android 開發(fā)手機(jī)(三星)拍照應(yīng)用照片旋轉(zhuǎn)問題解決辦法
這篇文章主要介紹了Android 開發(fā)手機(jī)(三星)拍照應(yīng)用照片旋轉(zhuǎn)問題解決辦法的相關(guān)資料,需要的朋友可以參考下2017-04-04
Android開發(fā)之獲取LayoutInflater對象的方法總結(jié)
這篇文章主要介紹了Android開發(fā)之獲取LayoutInflater對象的方法,結(jié)合實(shí)例形式總結(jié)分析了Android獲取LayoutInflater對象的常用技巧,需要的朋友可以參考下2016-02-02
Android編程使用android-support-design實(shí)現(xiàn)MD風(fēng)格對話框功能示例
這篇文章主要介紹了Android編程使用android-support-design實(shí)現(xiàn)MD風(fēng)格對話框功能,涉及Android對話框、視圖、布局相關(guān)操作技巧,需要的朋友可以參考下2017-01-01

