vanpet Posted October 1, 2015 Share Posted October 1, 2015 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 More sharing options...
rich Posted October 1, 2015 Share Posted October 1, 2015 See ScaleManager.scrollTop method which controls this. You can disable it by setting the ScaleManager.compatibility.scrollTo property to false. samme and Pixelguy 1 1 Link to comment Share on other sites More sharing options...
axelraym Posted July 29, 2016 Share Posted July 29, 2016 I've been trying to solve this issue for hours and finally found the solution here! I literally just signed up to thank you all for this, so thanks a lot! Link to comment Share on other sites More sharing options...
Recommended Posts