上船界面见下图:
汇智学堂-JS菜鸟版过河小游戏(之二---测试父母上船)
页面修改代码

<div id="div1" class="a1">
			<img src="img/father.jpg" "fathermove1()" />
		</div>	
		
		<div id="div2" class="a2">
			<img  src="img/mother.jpg" "mothermove1()"/>
		</div>
<div>

JS函数:

<!--上船-->

var shipposition1=0;
var shipposition2=0;

function upship(div11){
	var div1=document.getElementById(div11);
	
	if(div1.style.marginLeft=="0px"||div1.style.marginLeft==""){
		div1.style.marginTop="600px"; 
		if(shipposition1==0){		
	  	 div1.style.marginLeft="210px";	
	  	 shipposition1=1;
	   }
		else if(shipposition2==0){
		 div1.style.marginLeft="110px";	
		 shipposition2=1;
	   }
		else{
			alert('船上人已满!');
		}
  }
}

<!--爸爸上船-->

function fathermove1(){
	upship("div1");	
}
<!--妈妈上船-->
function mothermove1(){
	upship("div2");
}
`

相关文章:

  • 2021-08-12
  • 2021-07-21
  • 2021-05-05
  • 2021-04-18
  • 2021-04-22
  • 2021-08-18
  • 2021-05-25
  • 2021-06-06
猜你喜欢
  • 2021-10-13
  • 2021-11-06
  • 2021-06-18
  • 2021-12-09
  • 2022-01-19
  • 2022-01-02
  • 2021-12-25
相关资源
相似解决方案