У меня есть HTML-страница, разбитая на DIVS. Каждый div содержит определенный раздел. Одновременно отображается только один раздел. Мое требование - обновлять каждую секцию, когда она перемещается из одной секции в другую. Пожалуйста, обратите внимание на код в ниже URL,Обновить/Обновить раздел страницы с помощью jquery
http://jsfiddle.net/martyk/VE4sU/15/ код JQuery,
// overwrite $jScroller to supply asynchronous callback when end has been reached:
$jScroller.scroll = function() {
for (var i in $jScroller.config.obj) {
if ($jScroller.config.obj.hasOwnProperty(i)) {
var
obj = $jScroller.config.obj[i],
left = Number(($jScroller.get.px(obj.child.css('left'))||0)),
top = Number(($jScroller.get.px(obj.child.css('top'))||0)),
min_height = obj.parent.height(),
min_width = obj.parent.width(),
height = obj.child.height(),
width = obj.child.width();
if (!obj.pause) {
switch(obj.direction) {
case 'up':
if (top <= -1 * height) {
$jScroller.stop();
obj.child.css('top','0px');
manager.callback();
break;
}
obj.child.css('top',top - obj.speed + 'px');
break;
case 'right':
if (left >= min_width) {left = -1 * width;}
obj.child.css('left',left + obj.speed + 'px');
break;
case 'left':
if (left <= -1 * width) {left = min_width;}
obj.child.css('left',left - obj.speed + 'px');
break;
case 'down':
if (top >= min_height) {top = -1 * height;}
obj.child.css('top',top + obj.speed + 'px');
break;
}
}
}
}
}
$jScroller.start = function() {
if ($jScroller.cache.timer === 0 && $jScroller.config.refresh > 0) {
$jScroller.cache.timer = window.setInterval($jScroller.scroll, $jScroller.config.refresh);
}
};
$(document).ready(function() {
function SectionManager() {
this.delayShortList = 15000;
this.marginShortList = 12;
this.currentSection = null;
this.sections = $("#content .section");
this.numSections = this.sections.length;
this.transition = function(){
//SCROLLER CODE STARTS HERE....
$jScroller.config.refresh = 100;
// Add Scroller Object
$jScroller.config.obj = [];
$jScroller.add(
"#content .section.active .activityTbl"
,"#content .section.active .activityTbl > table"
,"up"
, 3
);
// Start Autoscroller
$jScroller.start();
$jScroller.cache.init = true;
//SCROLLER CODE ENDS HERE....
};
this.onFullCycleCompleted = function() {
//window.location.replace(window.location.href);
alert("the following will trigger a page reload (UNLESS run from within jsfiddle): window.location.replace(window.location.href);");
};
this.callback = function() {
if (this.currentSection >= this.numSections-1) {
this.onFullCycleCompleted();
};
this.currentSection = (this.currentSection != null)
? (this.currentSection + 1) % this.numSections
: 0
;
$("#content .section").removeClass("active");
var $currentSection = $("#content .section:eq(" + this.currentSection + ")");
$currentSection.addClass("active");
var itemCount = $(".activityTbl table.data tr", $currentSection).length;
if (itemCount < this.marginShortList) {
setTimeout(function() {
manager.transition();
}, this.delayShortList);
} else {
this.transition();
};
};
this.run = function(){
this.callback();
};
}
manager = new SectionManager();
manager.run();
});
страница в основном отображает Activity1 затем деятельности2 и так далее. Мое требование - обновить содержимое, когда оно перемещается из Activity1 в Activity2 перед его отображением. Таким образом, у меня может быть самая последняя информация с сервера.
это звучит так, будто вы хотите, чтобы мы сделали вашу работу за вас .. где вы точно застряли? это слишком много кода, который вы там встали .. вы должны попытаться изолировать свою проблему и упростить ее. – abbood
Текущий код обновляет страницу после завершения всего цикла. Но я не знаю, как обновить страницу между разделами. Таким образом, в приведенной выше строке кода this.callback = function() { if (this.currentSection> = this.numSections-1) { this.onFullCycleCompleted(); }; обновляет страницу после всего цикла. Я не уверен, как настроить его, а не весь цикл он обновляется после каждого раздела. – developer