這段代碼將圖像拖到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