これらのコードを使用するよりも、別の画像を表示する必要がありますが、マウスが画像を表示するリストであるリスデルの上にあると、マウスアウトイベントを受け取るため消えます。説明するのは非常に難しいですが、デバッグしてみて、表示される画像内でマウスを動かしてみてください。
<script>
var mouseOverListDel = false;
// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all ? true : false
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0
// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft
tempY = event.clientY + document.body.scrollTop
} else { // grab the x-y pos.s if browser is NS
tempX = e.pageX
tempY = e.pageY
}
// catch possible negative values in NS4
if (tempX < 0) { tempX = 0 }
if (tempY < 0) { tempY = 0 }
// show the position values in the form named Show
// in the text fields named MouseX and MouseY
var txbX = document.getElementById('TextBox1');
var txbY = document.getElementById('TextBox2');
txbX.value = tempX;
return true
}
function getPosition(element) {
var xPosition = 0;
var yPosition = 0;
while (element) {
xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
element = element.offsetParent;
}
return { x: xPosition, y: yPosition };
}
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// Loop through the FileList and render image files as thumbnails.
for (var i = 0, f; f = files[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function (theFile) {
return function (e) {
// Render thumbnail.
var span = document.createElement('span');
span.innerHTML = ['<img class="thumb" src="', e.target.result,
'" title="', escape(theFile.name), '"/>'].join('');
span.style.height = "65px";
span.style.width = "90px";
document.getElementById('list').insertBefore(span, null);
var del = document.createElement('del');
del.style.visibility = "hidden";
del.innerHTML = ['<img class="thumbdel" src="http://s7.postimage.org/fc6w3qjp3/del.png',
'" title="', escape(theFile.name + "del"), '"/>'].join('');
document.getElementById('listdel').insertBefore(del, null);
del.addEventListener("click", function () { delClick(del, span) }, false);
del.addEventListener('mouseover', function () { opacityOn(del) }, false)
del.addEventListener('mouseout', function () { opacityOn(del) }, false);
span.addEventListener('mouseover', function () { opacityOn(del) }, false);
span.addEventListener('mouseout', function () { opacityOff(del) }, false);
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
}
function delClick(imgDel, img)
{
var listImg = document.getElementById('list');
listImg.removeChild(img);
var listDelImg = document.getElementById('listdel');
listDelImg.removeChild(imgDel);
}
function opacityOn(imgDel)
{
imgDel.style.visibility = "visible";
}
function opacityOff(imgDel)
{
imgDel.style.visibility = "hidden";
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>