View Full Version : رفتن به بالای page بعد از دستور prompt
sanaz.dadkhah
دوشنبه 01 آبان 1391, 08:15 صبح
سلام من دارم از prompt استفاده میکنم بعد از نمایش متاسفانه صفحه به بالا انتفال داده میشود
اگر نخاهم که به بالای صفحه بروم و در اصل scrool همون حا باشه چگونه بای عمل کنم؟
hakan648
شنبه 20 آبان 1391, 23:51 عصر
سلام
باید قبل از نمایش Prompt موقعیت اسکرول رو ذخیره کنی و بعد از نمایش اسکرول هم اسکرول رو به موقیت قبلی منتقل کنی.
برای یک پروژه ی چت ، یک کلاس ساده برای مدیریت اسکرول نوشتم ، میتونی تغییرش بدی مطابق نیازت .
اگر هم راهنمایی بیشتری نیاز داشتی بگو .
var ChatHelper = function () {
var inputBox;
var messageBoxId;
var objScrollPosition = { top: 0, isAtBottom: true };
var init = function (inputId, boxId) {
inputBox = document.getElementById(inputId);
messageBoxId = boxId;
};
var onWindowLoad = function () {
var messageBox = getMessageBox();
if (!messageBox) {
return;
}
messageBox.scrollTop = messageBox.scrollHeight;
if (inputBox) {
inputBox.focus();
}
};
var onBeginRequest = function (sender, args) {
var messageBox = getMessageBox();
if (!messageBox) {
return;
}
if (!isAtBottom(messageBox)) {
objScrollPosition.isAtBottom = false;
objScrollPosition.top = messageBox.scrollTop;
} else {
objScrollPosition.isAtBottom = true;
objScrollPosition.top = 0;
}
};
var onEndRequest = function (sender, args) {
var messageBox = getMessageBox();
if (!messageBox) {
return;
}
if (!objScrollPosition.isAtBottom) {
messageBox.scrollTop = objScrollPosition.top;
} else {
messageBox.scrollTop = messageBox.scrollHeight;
}
};
function isAtBottom(elem) {
var oldPos = elem.scrollTop;
var newPos;
elem.scrollTop = oldPos + 1;
newPos = elem.scrollTop;
elem.scrollTop = oldPos;
if (newPos == oldPos) {
return true;
}
else {
return false;
}
}
function getMessageBox() {
return document.getElementById(messageBoxId);
}
return {
init: init,
beginRequest: onBeginRequest,
endRequest: onEndRequest,
windowLoad: onWindowLoad
};
};
vBulletin® v4.2.5, Copyright ©2000-1403, Jelsoft Enterprises Ltd.