这段代码将图像拖到DOM元素后添加图像。更改DOM后执行jQuery
var showImage = function (ev) {
var file = ev.target.file;
var thumb = new Image(100,100);
thumb.src = ev.target.result;
thumb.className = 'thumbFoto';
thumb.title = file.name;
thumb.alt = file.name;
var anchor = document.createElement('a');
anchor.className = 'thumbLink';
anchor.href = ev.target.result;
anchor.rel = 'album1';
anchor.title = file.name;
anchor.appendChild(thumb);
dropZone.appendChild(anchor);
}
这个代码链接到使用
<script type="text/javascript" src="js/code.js"></script>
后的图像添加到网页的页面,我想用的fancybox预览。 当页面加载(之前我拖着任何图像到它),这个脚本在HTML头执行:
<script type="text/javascript">
$(document).ready(function() {
/* Apply fancybox to albums */
$("a.thumbLink").fancybox();
});
</script>
现在我该怎样确保我可以预览使用的fancybox最近添加的图片吗?
如何拖动图像?你应该调用'$(“a.thumbLink”)。fancybox();'在stop()'拖动事件。 – SubRed
如果您使用的是fancybox v1.3.4,该版本不支持动态添加的元素。查看http://stackoverflow.com/a/9084293/1055987了解解决方法。版本2.x使用'live',所以你只需要正常初始化fancybox。 – JFK
@JFK非常感谢! – user1879060