如何通过html5存储api存储然后加载内容?

时间:2014-01-31 13:05:15

标签: javascript jquery html5 local-storage overscroll

1 - 我有这张地图:WATCH!

2 - 当我有这个代码时,如何用HTML5存储存储地图位置:

var PlanetRefreshTimeSec = 1;//planet refresh time in seconds..
function loadData() {
    $("#show_planet_realtime").load("../in/GameEngine/RealTimeRender.php?p=<?php echo $player; ?>", function () {
        setTimeout( function () {
            loadData();
        }, PlanetRefreshTimeSec * 1000);
    });
}
$( function () {
    loadData();
});

我已编写此代码,但似乎无法正常工作..:

var PlanetRefreshTimeSec = 1;//planet refresh time in seconds..
function loadData() {

    $.ajaxSetup({
        cache: false
    });

    var updatePosition = function() {
        var div = $('#show_planet_realtime');
        setTimeout(function(){div.scrollTop(div.height())},200);
    };
    $("#show_planet_realtime").load("../in/GameEngine/RealTimeRender.php?p=<?php echo $player; ?>", updatePosition, function () {
        setTimeout( function () {
            loadData();
        }, PlanetRefreshTimeSec * 1000);
    });
}
$( function () {
    loadData();
});

请告诉我,在刷新页面时如何使地图位置保持在坐标上?

1 个答案:

答案 0 :(得分:0)

加载后,你可以这样保存坐标:

localStorage.setItem("coords-player23423", coords);

重新加载设置后与存储中的坐标

var coords = localStorage.getItem("coords-player23423");
player.updateCoords( coords );