如何制作一个暂停代码然后再次启动它的按钮 [英] How to make a button that pauses code but then starts it again

查看:77
本文介绍了如何制作一个暂停代码然后再次启动它的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Html和javascript中进行文字冒险。我有几乎所有我需要的东西,除了你在播放时向下滚动网页的方式。



 var start = function( ){//开放房间
而(选择!=门||窗口){
document.write(< p>有一扇门, 你坐在其中,南边是一个小窗户,微风吹过< / p>);
document.write(< p> inspect'gate'inspect'window'< / p>);
var choice = window.prompt(门或窗);
if(choice ==door){
document.write(< p>你站起来,在你的关节疼痛你咕噜咕噜。检查你看到的门,似乎是什么,a大铁磨碎的细胞门?''我为什么要进入细胞?''你想想自己。< / p>)
startDoor()
break;
}否则如果(选择==窗口){
document.write(< p>你站起来,在你的关节疼痛你咕噜咕噜。检查窗口< / p>);

startWindow()
break;
} else {
document.write(< p>请输入显示的选项< / p>);
};
};
};





我试图在它开始之前放一个按钮然后询问点击继续但是我不能使用确认或任何东西,因为我需要能够向下滚动。或者如果我可以使提示框或确认框不阻止使用浏览器。



这个脚本是在html中调用的,所以我知道它的工作原理,只需要让它暂停或者不知何故



我尝试了什么:



我尝试了很多东西,但我不认为它甚至接近于什么我需要。我试过按钮在Html和java中单击我,并广泛搜索了w3schools网站。

解决方案

在页面上填写内容时向下滚动到页面

使用 window.scrollTo [ ^ ]

  window  .scrollTo( 0  document  .body.scrollHeight); 


Im making a Text adventure in Html and javascript. I have almost everything I need for it except a way for you to scroll down on the web page while playing.

var start = function(){//The opening room
		while(choice != "door" || "window") {
			document.write("<p>There's a door north of which you sit, south is a small window with a slight breeze coming through</p>");
			document.write("<p> inspect 'door'  inspect 'window'</p>");
			var choice = window.prompt("door or window");
			if(choice == "door"){
				document.write("<p>You stand up, aching in your joints you grunt. Inspecting the door you see, what seems to be, a large iron grated cell door? ''Why would I be in a cell?'' you think to yourself.</p>")
				startDoor()
				break;
			}else if(choice == "window"){
				document.write("<p>You stand up, aching in your joints you grunt. Inspecting the window</p>");
				
				startWindow()
				break;
			}else {
				document.write("<p>Please type the choices as shown</p>");
		};
	};
};



Im trying to put a button in this so before it starts it asks "click to continue" but I can't use confirm or anything because I need then to be able to scroll down. Or If I can make the prompt boxes or confirm boxes not block use of the browser.

This script is being called in the html so it I know it works, just need to let it pause or something somehow

What I have tried:

I've tryed many things but I dont think it was even close to what I need. Ive tried the button click me in both Html and java and have searched the w3schools website extensively.

解决方案

for scrolling down to the page when the content is filled on the page
use window.scrollTo[^]at the end of your javascript function

window.scrollTo(0,document.body.scrollHeight);


这篇关于如何制作一个暂停代码然后再次启动它的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆