我有一个拖放教育程序,可以在Windows touch平板电脑和设备上完美运行。但是当我在iPad上访问相同的程序时,当使用jQuery动态更改图像时,背景图像会消失。以下是其中一个功能的代码。消失的背景图像以四条线开始“var OldImage = ...在具有最新版本iOS的新旧iPad上的结果相同。提前感谢!
function PasteOld1() {
animal1.addEventListener('touchmove', function(event) {
var touch = event.targetTouches[0];
animal1.style.left = touch.pageX-100 + 'px';
animal1.style.top = touch.pageY-100 + 'px';
var p1 = animal1.style.left;
var xpos = document.getElementById("inputP1");
xpos.value = p1;
var p2 = animal1.style.top;
var ypos = document.getElementById("inputP2");
ypos.value = p2;
event.preventDefault();
}, false);
var P1 = document.getElementById('inputP1').value;
P1 = P1.slice(0,3);
//determines if first touch is image1; if so, copies image url to "old" div>
if (P1 > 100 && P1 < 300) {
var oldImage = $('#animal1').css('background-image');
oldImage = oldImage.slice(5);// removes first five characters of string
oldImage = oldImage.substring(0,oldImage.length-2); // removes last two characters of string
$('#old').css("backgroundImage","url('"+oldImage+"')");
}
}