cashloveyou
@cashloveyou
Хороший чел

History API + Magnific Popup?

Пытаюсь подсоединить history api к magnific popup
нашел интересный контент - https://github.com/EugeneDae/Magnific-Popup-Histor...
но как им воспользоваться если у меня вызывается popup через onclick? и далее контент подгружается через ajax , прошу помогите начинающим

Javascript
function Wo_OpenLightBox(post_id) {
  $('#contnet').append('<div class="lightbox-container"><div class="lightbox-backgrond" onclick="Wo_CloseLightbox();"></div><div class="lb-preloader" style="display:block"><svg width="50px" height="50px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid"><rect x="0" y="0" width="100" height="100" fill="none" class="bk"></rect><circle cx="50" cy="50" r="40" stroke="#676d76" fill="none" stroke-width="6" stroke-linecap="round"><animate attributeName="stroke-dashoffset" dur="1.5s" repeatCount="indefinite" from="0" to="502"></animate><animate attributeName="stroke-dasharray" dur="1.5s" repeatCount="indefinite" values="150.6 100.4;1 250;150.6 100.4"></animate></circle></svg></div></div>');
  $.get(Wo_Ajax_Requests_File(), {f:'open_lightbox', post_id:post_id}, function(data) {
    if (data.status == 200) {
      var url = post_id;
      history.pushState(null, title, url);
    document.body.style.overflow = 'hidden';
      $('.lightbox-container').html(data.html);
    }
    if (data.html.length == 0) {
       document.body.style.overflow = 'auto';
    }
  });
}


AJAX
if ($f == 'open_lightbox') {
    $html = '';
    if (!empty($_GET['post_id'])) {
        $wo['story'] = Wo_PostData($_GET['post_id']);
        if (!empty($wo['story'])) {
            $html = Wo_LoadPage('lightbox/content');
        }
    }
    $data = array(
        'status' => 200,
        'html' => $html
    );
    header("Content-type: application/json");
    echo json_encode($data);
    exit();
}
  • Вопрос задан
  • 184 просмотра
Пригласить эксперта
Ответы на вопрос 1
@frees2
history.js зачем, если можно получать историю и через
if (localStorage.getItem('history') === null) {    }
else{ document.getElementById( 'result' ).innerHTML =localStorage.getItem('history'); };

и через, а то и через то и другое
window.history
var i = 0;(function(history){ var pushState = history.pushState;
history.pushState = function(state) { if (typeof history.onpushstate == "function")
{history.onpushstate({state: state});} 
return pushState.apply(history, arguments); }})(window.history);
window.onpopstate = history.onpushstate = function(e){ i++; test=JSON.stringify(e.state);
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы