使用したいこのスクリプトを見つけましたが、画像に href を追加する方法がわかりません。
または、誰かがより良い方法または解決策を持っている場合。
divタグで画像を選択する方法が良いと思いますが、どうですか?
編集:
将来の参照のために要求されたように、ここにコードがありますBounceImage.js
// INITIALIZATION:
imagesDetails = new Array();
bouncingImages2 = new Object();
// CONFIGURATION:
imagesDetails[0] = new Object();
imagesDetails[0].width = 50;
imagesDetails[0].height = 50;
imagesDetails[0].src = 'logo1xMINI.jpg';
imagesDetails[1] = new Object();
imagesDetails[1].width = 40;
imagesDetails[1].height = 40;
imagesDetails[1].src = 'superball.gif';
imagesDetails[2] = new Object();
imagesDetails[2].width = 60;
imagesDetails[2].height = 50;
imagesDetails[2].src = "1.png";
// Template for further images:
// imagesDetails[3] = new Object();
// imagesDetails[3].width = ?;
// imagesDetails[3].height = ?;
// imagesDetails[3].src = '?';
bouncingImages2.frameRate = 30;
bouncingImages2.minRandomSpeed = 2;
bouncingImages2.maxRandomSpeed = 8;
// MAIN:
bouncingImages2.isLoaded = false;
var winWidth, winHeight;
if (dyn) {
for (var imageLoop = 0; imageLoop < imagesDetails.length; imageLoop++) imagesDetails[imageLoop].imgObj = loadImg(imagesDetails[imageLoop].src);
}
function getWindowDimensions() {
winWidth = getWinWidth();
winHeight = getWinHeight();
}
function loadBouncingImages2() {
if (dyn && !bouncingImages2.isLoaded) {
getWindowDimensions();
for (var layerLoop = 0; layerLoop < imagesDetails.length; layerLoop++) {
imagesDetails[layerLoop].dirX = (Math.round(Math.random()) == 0) ? 'left' : 'right';
imagesDetails[layerLoop].dirY = (Math.round(Math.random()) == 0) ? 'up' : 'down';
imagesDetails[layerLoop].posX = Math.floor(Math.random() * (winWidth - imagesDetails[layerLoop].width - 1)) + getDocScrollLeft();
imagesDetails[layerLoop].posY = Math.floor(Math.random() * (winHeight - imagesDetails[layerLoop].height - 1)) + getDocScrollTop();
imagesDetails[layerLoop].speedX = Math.round(Math.random() * (bouncingImages2.maxRandomSpeed - bouncingImages2.minRandomSpeed)) + bouncingImages2.minRandomSpeed;
imagesDetails[layerLoop].speedY = Math.round(Math.random() * (bouncingImages2.maxRandomSpeed - bouncingImages2.minRandomSpeed)) + bouncingImages2.minRandomSpeed;
imagesDetails[layerLoop].layerObj = addLayer('bouncingImagesLyr' + layerLoop);
setLayerSize(imagesDetails[layerLoop].layerObj,imagesDetails[layerLoop].width,imagesDetails[layerLoop].height);
setLayerClip(imagesDetails[layerLoop].layerObj,0,imagesDetails[layerLoop].width,imagesDetails[layerLoop].height,0);
setLayerHTML(imagesDetails[layerLoop].layerObj,getImgTag('bouncingImagesImg' + layerLoop,imagesDetails[layerLoop].src,imagesDetails[layerLoop].width,imagesDetails[layerLoop].height,0));
moveLayerTo(imagesDetails[layerLoop].layerObj,imagesDetails[layerLoop].posX,imagesDetails[layerLoop].posY);
showLayer(imagesDetails[layerLoop].layerObj);
}
bouncingImages2.isLoaded = true;
moveBouncingImages();
}
}
function moveBouncingImages() {
for (var layerLoop = 0; layerLoop < imagesDetails.length; layerLoop++) {
if (imagesDetails[layerLoop].dirX == 'left') {
if (imagesDetails[layerLoop].posX > imagesDetails[layerLoop].speedX) imagesDetails[layerLoop].posX -= imagesDetails[layerLoop].speedX;
else {
imagesDetails[layerLoop].dirX = 'right';
imagesDetails[layerLoop].posX = 0;
}
}
else if (imagesDetails[layerLoop].dirX == 'right') {
if (imagesDetails[layerLoop].posX + imagesDetails[layerLoop].width < winWidth - imagesDetails[layerLoop].speedX) imagesDetails[layerLoop].posX += imagesDetails[layerLoop].speedX;
else {
imagesDetails[layerLoop].dirX = 'left';
imagesDetails[layerLoop].posX = winWidth - imagesDetails[layerLoop].width;
}
}
if (imagesDetails[layerLoop].dirY == 'up') {
if (imagesDetails[layerLoop].posY > imagesDetails[layerLoop].speedY) imagesDetails[layerLoop].posY -= imagesDetails[layerLoop].speedY;
else {
imagesDetails[layerLoop].dirY = 'down';
imagesDetails[layerLoop].posY = 0;
}
}
else if (imagesDetails[layerLoop].dirY == 'down') {
if (imagesDetails[layerLoop].posY + imagesDetails[layerLoop].height < winHeight - imagesDetails[layerLoop].speedY) imagesDetails[layerLoop].posY += imagesDetails[layerLoop].speedY;
else {
imagesDetails[layerLoop].dirY = 'up';
imagesDetails[layerLoop].posY = winHeight - imagesDetails[layerLoop].height;
}
}
}
for (var layerLoop = 0; layerLoop < imagesDetails.length; layerLoop++) moveLayerTo(imagesDetails [layerLoop].layerObj,imagesDetails[layerLoop].posX + getDocScrollLeft(),imagesDetails [layerLoop].posY + getDocScrollTop());
window.setTimeout('moveBouncingImages()',bouncingImages2.frameRate);
}
window.onresize = getWindowDimensions;
window.onload = loadBouncingImages2;
ここでは lib.js が長すぎます
ボディタグ内
<body onLoad="javascript:loadBouncingImages2();">