Loading...
Приветствую друзья. Суть проблемы
Проблема с возвратом страницы в нужное положение? Суть в том что всё получилось, но допустим я зашел на главную, пролистал до середины, после этого перешел в почту, вернулся кнопкой браузера назад на главную, меня вернуло на позицию с которой переходил в почту, но теперь если я буду заходить на главную с других страниц, то она всегда остается на середине, то есть на той позиции с которой я перешёл на какую либо страницу



$(document).on('click', 'a[ajax != "no"]', function(e){
var link = $(this).attr('href');

if (link != null){
sessionStorage.setItem('scrollPosition', window.scrollY);
e.preventDefault();
go_url(link);
var title_ajax = document.title;
history.pushState({ path: link }, title_ajax, link);
}
});

if (history.pushState) {
$(window).on('popstate', function(event) {
var location = event.state ? event.state.path : document.location.href;
go_url(location);
});
}

function go_url(href) {
var ajax_load = href + ' #content';
var ajax_indication = $('.ajax_indication').attr('data');

$('#ajax_load').fadeOut(400);
$('.ajax_indication').html('<i class="fa fa-spinner fa-spin"></i><span>' + ajax_indication + '</span>').fadeIn(400);

setTimeout(function() {
$("#content").load(ajax_load, function(data, status) {
if (status == "success") {
var savedPosition = sessionStorage.getItem('scrollPosition');
if (savedPosition !== null) {
setTimeout(function() {
window.scrollTo(0, savedPosition);
}, 0);
}

if ($(".scroll").hasClass("bottom")) {
document.body.scrollTop = document.body.scrollHeight;
document.documentElement.scrollTop = document.body.scrollHeight;
} else {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}

js_hooks();
}
});
}, 130);
}

function ajax_post(o) {
var $that = $('.ajax-form' + o);
var link = $that.attr('action');

$.post(link, $that.serialize(), function(data) {
var elem = $(data).filter('#content').html();
$("#content").html(elem);

var savedPosition = sessionStorage.getItem('scrollPosition');
if (savedPosition !== null) {
setTimeout(function() {
window.scrollTo(0, savedPosition);
}, 0);
}

document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
var title_ajax = document.title;
history.pushState({ path: link }, title_ajax, link);
});
}

$(document).on('click', '.ajax-button', function(e) {
var bset = $(this);
var o = bset.attr('o');
ajax_post(o);
e.preventDefault();
});

$(document).on('click', '.ajax-button-search', function(e) {
$(this).html('<i class="fa fa-spinner fa-spin fa-fw" style="font-size: 20px"></i>');
ajax_post(2);
e.preventDefault();
});

$(document).on('click', '.ajax-button-search-web', function(e) {
$(this).html('<i class="fa fa-spinner fa-spin fa-fw" style="font-size: 20px"></i>');
ajax_post(999);
e.preventDefault();
});
Заменить строку

window.scrollTo(0, savedPosition);

на

if (/site.ru/.test(document.referrer)) {
window.scrollTo(0, savedPosition);
}

Вместо site.ru пишешь свой сайт
Скачай двиг visavi от туда можно скопировать код.
Georgian , а как он подойдёт, если у меня другой двиг?
Something , попробую, отпишусь
201275291 [!] (1 фев 2025, в 12:51)
Something , попробую, отпишусь
Я там херню написал, попробуй вот так

$(document).on('click', 'a[ajax != "no"]', function(e){
var link = $(this).attr('href');

if (link != null){
sessionStorage.setItem('scrollPosition', window.scrollY);
e.preventDefault();
go_url(link, false);
var title_ajax = document.title;
history.pushState({ path: link }, title_ajax, link);
}
});

if (history.pushState) {
$(window).on('popstate', function(event) {
var location = event.state ? event.state.path : document.location.href;
go_url(location, true);
});
}

function go_url(href, go_pos = false) {
var ajax_load = href + ' #content';
var ajax_indication = $('.ajax_indication').attr('data');

$('#ajax_load').fadeOut(400);
$('.ajax_indication').html('<i class="fa fa-spinner fa-spin"></i><span>' + ajax_indication + '</span>').fadeIn(400);

setTimeout(function() {
$("#content").load(ajax_load, function(data, status) {
if (status == "success") {
var savedPosition = sessionStorage.getItem('scrollPosition');
if (savedPosition !== null && go_pos === true) {
setTimeout(function() {
window.scrollTo(0, savedPosition);
}, 0);
}

if ($(".scroll").hasClass("bottom")) {
document.body.scrollTop = document.body.scrollHeight;
document.documentElement.scrollTop = document.body.scrollHeight;
} else {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}

js_hooks();
}
});
}, 130);
}

function ajax_post(o) {
var $that = $('.ajax-form' + o);
var link = $that.attr('action');

$.post(link, $that.serialize(), function(data) {
var elem = $(data).filter('#content').html();
$("#content").html(elem);

var savedPosition = sessionStorage.getItem('scrollPosition');
if (savedPosition !== null) {
setTimeout(function() {
window.scrollTo(0, savedPosition);
}, 0);
}

document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
var title_ajax = document.title;
history.pushState({ path: link }, title_ajax, link);
});
}

$(document).on('click', '.ajax-button', function(e) {
var bset = $(this);
var o = bset.attr('o');
ajax_post(o);
e.preventDefault();
});

$(document).on('click', '.ajax-button-search', function(e) {
$(this).html('<i class="fa fa-spinner fa-spin fa-fw" style="font-size: 20px"></i>');
ajax_post(2);
e.preventDefault();
});

$(document).on('click', '.ajax-button-search-web', function(e) {
$(this).html('<i class="fa fa-spinner fa-spin fa-fw" style="font-size: 20px"></i>');
ajax_post(999);
e.preventDefault();
});
Something , Отлично, работает как нужно. Дай Бог здоровья, братец. + поставить не могу к сожалению, не хватает чего то пишет. (((
201275291 [!] (1 фев 2025, в 14:01)
Something , Отлично, работает как нужно. Дай Бог здоровья, братец. + поставить не могу к сожалению, не хватает чего то пишет. (((
Ну может когда-нибудь потом поставишь, когда накопишь то что там нужно :-)
Something , пишет что нужно не менее 50 баллов рейтинга. Обязательно поставлю)
Онлайн: 1
Время:
Gen. 0.153
(c) ByMAS.RU 2010-2025