【发布时间】:2013-09-08 13:14:28
【问题描述】:
<div contenteditable="true" class="dropZone"></div>
<div class="imageHolder">
<div class="droppedImage"></div>
</div>
我有上面的html。页面上可能有一些“dropZone”div。但每一个都有以下事件绑定:
$('#lightbox').find('.dropZone').each(function(){
$(this).mouseover(function(){
// check the asset is an image
if( $(this).find('img').length > 0 ){
var src = $(this).find('img').first().attr('src'),
masterTestVal = 'mydomain';
$(this).empty();
// check the asset is from the image bin
if(src.search(masterTestVal) > 0){
var that = $(this).siblings('.imageHolder').find('.droppedImage'),
img = '<img src="'+src+'"/>';
that.html(img);
} else {
alert('Only images from your image bin are accepted here.');
}
} else {
if($(this).html().length > 0){
alert('Only images from your image bin are accepted here.');
$(this).empty();
}
}
});
});
这个想法很简单,用户可以从他们的“图像箱”拖放一个图像,另一个 div 加载在页面上,其中填充了一些预加载的图像。当用户将图像拖到“放置区”div 上时,上述 js 会启动,如果该图像来自我的域,则该图像将被复制到“droppedImage”div 中。
这很好用,但在 chrome 和 safari 中,用户只能执行一次此操作。在firefix中我可以无休止地重复这个动作。但是在 chome 和 safari 中似乎一滴之后 attr contenteditable 就丢失了还是什么?
有人有什么想法吗?
谢谢, 约翰
js 小提琴 - http://jsfiddle.net/n6EgH/1/
【问题讨论】:
-
你可以为此制作小提琴吗?
-
我支持减少测试用例的请求(使用众多工具之一:codepen.io、jsFiddle、JS Bin 等)。
-
你真的应该为此提供最后的 CSS...
-
嗨,好的,我已经在小提琴中重现了效果:jsfiddle.net/n6EgH/1
标签: javascript jquery html image