I am adding a div using this.add.dom().createFromCache() that needs scrolling. How would I accomplish that? Do I have to set the scene size accordingly and move the camera to do this? It seems like overkill.
Hi, @1schnitzel. Welcome to Phaser Forum.
Give us more information about what you want to accomplish and what youâve already done to add DOM elements to your scene.
Could you put some code to guides us to help you?
Hi @Thyebe, thanks for the welcome. My problem is that I wanted to fix something that is already working. In my index.html I had a modal div on top of my game div where I showed some info. When the player clicked the close button Iâd hide it with âdisplay:noneâ. The div was much taller than the game but scrolling wasnât an issue. Then I learned about add.dom() and I removed the modal div from my index.html, put the code in a modal.html and added it with âthis.add.dom().createFromCache(âmodal.htmlâ)â. Itâs displayed but I canât scroll the content. I think itâs because the parent div that Phaser creates automatically has a overflow:hidden style applied. Since Iâm having a ton of other issues and no time, I just went back to putting my modal in the index.html code. It works and it wasnât smart to break it chasing some âelegant solutionâ. I was just wondering if thereâs an easy solution to insert a scrollable div using the add.dom method.
Try:
<style>
/* Hide scrollbar for Chrome, Safari and Opera */
#main::-webkit-scrollbar {
display: none;
}
/* Hide scrollbar for IE, Edge and Firefox */
#main {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
#main{
height: {game config height};
}
</style>
<div id="main"></div>
To the topmost div in modal.html.
In the maingame.js, set origin to (0,0) like this:
this.add.dom().createFromCache(âmodal.htmlâ).setOrigin(0,0);