Jump to content

Scroll position reset on mobile


vanpet
 Share

Recommended Posts

Hi guys,

 

I have a strange problem: I load a minimal Phaser game via an AJAX request somewhere in my page, and the scroll positions resets on top of the page... only on mobile, it doesn't happen on desktop.

 

I don't know why and it's driving me crazy.

 

I have set up a minimal code that will reproduce the error on mobile. It is divided in two files.

 

First, the index html where the AJAX request is made:

<!DOCTYPE html><html><head>	<title>TEST</title>	<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.4.3/phaser.min.js"></script>	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script></head><body>	<div id="box" style="margin-top:2000px">		<div id="test"></div>	</div>	<button id="btnload">LOAD</button>	<script type="text/javascript">		$("#btnload").click(function() {			$.ajax({	            type: "GET",	            url: "test2.html",	            success: function(response) {	                $('#test').html(response);	            },	            complete: function(xhr, status) {},	            error: function()	            {	                alert("Error : could not connect to server");	            }	        });	       return false;		});	</script></body></html>

Then the second file that is used to give a response to the AJAX request (that is, an empty Phaser game) :

<script type="text/javascript">// GAME OBJECTvar game = new Phaser.Game(  550, // width  380, // height  Phaser.CANVAS, // renderer (CANVAS for better compatibility)  'test', // container HTML ID  { preload: preload, create: create, update: update }, // available functions  false // transparent background);function preload() {}function create() {	game.stage.backgroundColor = '#000000';}function update() {}</script>

When clicking on the "LOAD" button in index, the Phaser is correctly loaded, but the page resets itself on top. That is not wanted. How can I avoid this problem?

Link to comment
Share on other sites

  • 9 months later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...