我已经构建了以下幻灯片来检索...的内容
<li title=""> and <a title="">
...并将其显示在
<h2> & <h3>
....在下方,同时将鼠标悬停在每张幻灯片图片上。当 onmouseover 未激活时,标题标签将被清除并返回其默认状态。
HTML:
<ul class="slideshow">
<li id="picture-1" title="Picture Title" onmouseover="pictureTitle(this)" onmouseout="clearPicture()">
<a title="Picture Description" onmouseover="pictureDescription(this)" href="#">
<img src="images/picture-1.png">
</a>
</li>
<li id="picture-2" title="Picture 2 Title" onmouseover="pictureTitle(this)" onmouseout="clearPicture()">
<a title="Picture 2 Description" onmouseover="pictureDescription(this)" href="#">
<img src="images/picture-2.png">
</a>
</li>
<li id="picture-3" title="Picture 3 Title" onmouseover="pictureTitle(this)" onmouseout="clearPicture()">
<a title="Picture 3 Description" onmouseover="pictureDescription(this)" href="#">
<img src="images/picture-3.png">
</a>
</li>
</ul>
<h2 id="picture-notitle">Default Picture Title</h2>
<h2 id="picture-title"></h2>
<h3 id="picture-nodescription">Default Picture Description</h3>
<h3 id="picture-description"></h3>
Javascript:
function pictureTitle(li) {
var name = document.getElementById("picture-title");
name.innerText = li.title;
name.style.display = "block";
document.getElementById("picture-notitle").style.display = "none";
}
function pictureDescription(a) {
var description = document.getElementById("picture-description");
description.innerText = a.title
description.style.display = "block";
document.getElementById("picture-nodescription").style.display = "none";
}
function clearPicture() {
document.getElementById("picture-notitle").style.display = "block";
document.getElementById("picture-title").style.display = "none";
document.getElementById("picture-nodescription").style.display = "block";
document.getElementById("picture-description").style.display = "none";
}
CSS:
#picture-title, #picture-description {
display: none;
}
幻灯片按预期工作;悬停图片显示其“标题”和“描述”。不过,我在构建它时遇到了麻烦。我希望能够在将鼠标悬停在一组文本上时调用 pictureTitle() 和 pictureDescription() 函数,而不是实际图像本身。
<h1>
<span>Picture 1</span>
<span>Picture 2</span>
<span>Picture 3</span>
</h1>
我已经尝试在 span 标签上使用 onmouseover 调用这些函数,但无法让任何工作。
有任何想法吗?