javascript - 在 Javascript 幻灯片放映上添加文本

标签 javascript html css

我尝试在 javascript 幻灯片放映中添加一些文本,但不知何故它不起作用。文本显示在顶部,幻灯片在文本下方循环播放。

如何让文字正确显示在图片上?请看一下

<html>
<head>
<script type="text/javascript">
<!--
var image1=new Image()
image1.src="firstcar.gif"
var image2=new Image()
image2.src="secondcar.gif"
var image3=new Image()
image3.src="thirdcar.gif"
//-->
</script>
</head>
<body>
<div style="width:100px; height:56px">
    <div style="width:100px; height:56px; z-index:2">Tring to add some text on the top
        <div style="width:100px; height:56px; z-index:1">
              <img src="firstcar.gif" name="slide" width="100" height="56" />
        </div>
    </div>
</div>
<script>
<!--

var step=1
function slideit(){
if (!document.images)
return
document.images.slide.src=eval("image"+step+".src")
if (step<3)
step++
else
step=1
setTimeout("slideit()",1500)
}
slideit()
//-->
</script>
</body>
</html>

最佳答案

如果你想使用 z-index,你可能需要 position: absolute

或者您可以将 img 的高度降低到小于文本的 div 容器

试试这个:

 <body>
 <div style="width:100px; height:56px">
 <div style="position:absolute; z-index:2">Tring to add some text on the top

</div>
 <div style="position: absolute;width:100px; height:56px; z-index:1">
          <img src="firstcar.gif" name="slide" width="100" height="56" />
    </div>
</div>
</body>

关于javascript - 在 Javascript 幻灯片放映上添加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19393162/

相关文章:

javascript - Mongodb Nodejs : return undefined after callback of an exported function

javascript - 显示一条消息直到 php 脚本完成

html - 信号动画不适用于 jsFiddle

javascript - 输入字段中值更改时的 Css 更改。查询

javascript - TR中选中和取消选中复选框的最佳方法

javascript - 单击 php 页面中的那个 div 时如何隐藏标题 "City"?

javascript - 如何使用 D3(或只是 javascript)将表单选项设置为 "selected"

php - 在 Wordpress 网站之前添加一个简单的 HTML 登陆页面

html - CSS:如何相对于居中的背景图像重新定位 <divs>

css - 获取 :hover to adjust more than one class/id