如何检查图像长宽比,如果图像长宽比大于则删除 div,然后删除图像,如果图像长宽比小于 div,则不删除图像
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function drop(ev) {
ev.preventDefault();
ev.target.appendChild(document.getElementById(data));
}
最佳答案
我想您只是想检查放置功能中的纵横比,然后允许或不允许插入图像。
function drop(ev) {
ev.preventDefault();
var divRatio = $('#div').width() / $('#div').height();
var imageRatio = $('#div').width() / $('#div').height();
if (imageRatio <= divRatio) {
ev.target.appendChild(document.getElementById(data));
}
}
关于javascript - 如何在将图像放入 div 之前检查图像的长宽比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43225316/