Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将一个div的移动链接到另一个div的移动_Javascript_Html - Fatal编程技术网

Javascript 将一个div的移动链接到另一个div的移动

Javascript 将一个div的移动链接到另一个div的移动,javascript,html,Javascript,Html,我正在制作一个酒精模拟器,所以当我按下一个按钮时,你会看到一个酒瓶正在倒掉,但同时我会看到胃在充盈。我已经有了“饮用”的代码,但我想修正一下,如果瓶子里的水移动了两步,那么胃里的水只移动了一步。我会把js放在这里,如果你也需要html,请告诉我 var top_max = 475, top_min = 400, left_max = 200; function move_img(str) { var step = 1; // change this to different step

我正在制作一个酒精模拟器,所以当我按下一个按钮时,你会看到一个酒瓶正在倒掉,但同时我会看到胃在充盈。我已经有了“饮用”的代码,但我想修正一下,如果瓶子里的水移动了两步,那么胃里的水只移动了一步。我会把js放在这里,如果你也需要html,请告诉我

var top_max = 475,
top_min = 400,
left_max = 200;

function move_img(str) {
    var step = 1; // change this to different step value
    var el = document.getElementById('i1');
    var el2 = document.getElementById('i2');

if (str == 'up' || str == 'down') {
    var top = el.offsetTop;
    var height = el.offsetHeight;
    console.log(height);
    if (str == 'up') {
        top -= step;
        height += step;
    } else {
        top += step;
        height -=step;
    }
    if (top_max >= top && top >= 110) {
        document.getElementById('i1').style.top = top + "px";
        document.getElementById('i1').style.height = height;
    } else {
        clearInterval(myVar)
    }
} else if (str == 'left' || str == 'right') {
    var left = el.offsetLeft;
    if (str == 'left') {
        left += step;
    } else {
        left -= step;
    }
    if (top_left < left && left >= 0) {
        document.getElementById('i1').style.left = top + "px";
    } else {
        clearInterval(myVar)
    }
}



}


function auto(str) {
    myVar = setInterval(function () {
        move_img(str);
    }, 90);
}

function nana() {}

var myVar;

function handler() {
    clearInterval(myVar);
    auto(this.id);
}



function auto(str) {

 myVar = setInterval(function(){ move_img(str); }, 2)  ;



}


function stop(){

setTimeout(function( ) { clearInterval( myVar ); }, 1);


}
var top_max=475,
顶部最小值=400,
左_max=200;
功能移动\u img(str){
var step=1;//将其更改为不同的步长值
var el=document.getElementById('i1');
var el2=document.getElementById('i2');
如果(str='up'| | str=='down'){
var top=标高偏移;
var高度=el离地高度;
控制台。原木(高度);
如果(str=='up'){
顶部-=台阶;
高度+=步长;
}否则{
顶部+=台阶;
高度-=台阶;
}
如果(顶部最大值>=顶部和顶部>=110){
document.getElementById('i1')。style.top=top+“px”;
document.getElementById('i1')。style.height=高度;
}否则{
清除间隔(myVar)
}
}else if(str='left'| | str=='right'){
var left=el.offsetLeft;
如果(str=='left'){
左+=步进;
}否则{
左-=台阶;
}
如果(左上=0){
document.getElementById('i1').style.left=top+“px”;
}否则{
清除间隔(myVar)
}
}
}
自动功能(str){
myVar=setInterval(函数(){
移动img(str);
}, 90);
}
函数nana(){}
var-myVar;
函数处理程序(){
净距(myVar);
自动(this.id);
}
自动功能(str){
myVar=setInterval(函数(){move_img(str);},2);
}
函数停止(){
setTimeout(函数(){clearInterval(myVar);},1);
}

把它做一个完整的描述,让我们看看它的实际效果,因为某种原因,他们从来都不为我工作