如何制作一个暂停代码然后再次启动它的按钮

编程入门 行业动态 更新时间:2024-10-10 12:19:52
本文介绍了如何制作一个暂停代码然后再次启动它的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在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);

更多推荐

如何制作一个暂停代码然后再次启动它的按钮

本文发布于:2023-10-17 09:20:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1500456.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!