Javascript 如何缓冲图像、在需要时显示图像以及如何移动图像
我一直在寻找如何做到这一点,但不知道怎么做。我所做的最好的事情就是用HTML制作一个图像。我试图编辑图像设置,就像使用Javascript 如何缓冲图像、在需要时显示图像以及如何移动图像,javascript,image,animation,Javascript,Image,Animation,我一直在寻找如何做到这一点,但不知道怎么做。我所做的最好的事情就是用HTML制作一个图像。我试图编辑图像设置,就像使用document.getElementById()来更改文本一样,但我无法让它工作 我的代码到目前为止 function run() { x++; y++; if (x==10 || x==30) { exmp.visibility = show //doesn't work } if (x==20 || x==40
document.getElementById()
来更改文本一样,但我无法让它工作
我的代码到目前为止
function run() {
x++;
y++;
if (x==10 || x==30) {
exmp.visibility = show //doesn't work
}
if (x==20 || x==40) {
exmp.visibility = hidden //doesn't work
}
if (x==50) {
x=0
y=0
}
document.getElementById("exmp").style = "position:absolute; TOP:0px; LEFT:0px; WIDTH:239px; HEIGHT:74px" //doesn't work
}
x=0
y=0
document.write("<div ID=\"exmp\"; STYLE=\"position:absolute; TOP:0px; LEFT:0px; WIDTH:239px; HEIGHT:74px\"> <IMG SRC=\"exmp.png\"; alt=\"image\"> </div>");
setInterval(run,33);
函数运行(){
x++;
y++;
如果(x==10 | | x==30){
exmp.visibility=show//不起作用
}
如果(x==20 | | x==40){
exmp.visibility=hidden//不起作用
}
如果(x==50){
x=0
y=0
}
document.getElementById(“exmp”).style=“位置:绝对;顶部:0px;左侧:0px;宽度:239px;高度:74px”//不起作用
}
x=0
y=0
文件。填写(“”);
设置间隔(运行,33);
有几种方法可以做到这一点
我终于找到了一个关于移动图像并在需要时显示它们的优秀java脚本教程。(http://www.openjs.com/tutorials/advanced_tutorial/moving.php) 我的工作代码:
<html>
<head>
<title>Image Mover</title>
<style>
DIV.movable { position:absolute; }
</style>
</head>
<body>
<div ID="exmp"; class = "movable";>
<IMG SRC="exmp.png"; alt="image"/>
</div>
<script type="text/javascript">
document.getElementById("exmp").style.visibility='hidden';
function run() {
pos++;
if (pos==10 || pos==30) {
document.getElementById("exmp").style.visibility='visible';
}
if (pos==20 || pos==40) {
document.getElementById("exmp").style.visibility='hidden';
}
if (pos==40) {
pos=0;
}
//document.getElementById("exmp").style = "position:absolute; TOP:"
// +pos+"px; LEFT:"+pos+"px; WIDTH:239px; HEIGHT:74px";
document.getElementById("exmp").style.left = pos+"px";
document.getElementById("exmp").style.top = pos+"px";
//STYLE="position:absolute; TOP:0px; LEFT:0px; WIDTH:239px; HEIGHT:74px"
}
pos=0;
setInterval(run,33);
</script>
</body>
</html>
移动图像
DIV.movable{位置:绝对;}
document.getElementById(“exmp”).style.visibility='hidden';
函数运行(){
pos++;
如果(位置=10 | |位置=30){
document.getElementById(“exmp”).style.visibility='visible';
}
如果(位置==20 | |位置==40){
document.getElementById(“exmp”).style.visibility='hidden';
}
如果(位置==40){
pos=0;
}
//document.getElementById(“exmp”).style=“位置:绝对;顶部:”
//+pos+“px;左:“+pos+”px;宽度:239px;高度:74px”;
document.getElementById(“exmp”).style.left=pos+“px”;
document.getElementById(“exmp”).style.top=pos+“px”;
//STYLE=“位置:绝对;顶部:0px;左侧:0px;宽度:239px;高度:74px”
}
pos=0;
设置间隔(运行,33);
请显示您迄今为止尝试过的内容的摘录。您试图修改哪些“设置”?你想对这个图像做什么?让它在页面上飞来飞去?调整它的大小?把兔子拉出来?我们需要更多的细节来帮助我如何将图像设置为可见?更改元素的样式,例如:img{visibility:hidden;}