Reputation:
In demo user scroll to top it prepend the text(string value) .But it prepand the string. http://jsfiddle.net/G6jJS/12/
$("#fullContainer").scroll(function () {
// top
if ($(this).scrollTop() === 0) {
alert("up");
var stringLoad ="page_"+i--;
$( "<div id='"+stringLoad+"'>" +stringLoad+ "</div>").prependTo($("#fullContainer"));
}
if ($('this').scrollTop() >= $('this')[0].scrollHeight - document.body.offsetHeight) {
alert("down");
}
});
Upvotes: 0
Views: 49
Reputation: 32581
Use window[stringload]
to get the page_x variable and declare the pages as global variables.
$( "<div id='"+stringLoad+"'>" +window[stringLoad]+ "</div>").prependTo($("#fullContainer"));
Upvotes: 1
Reputation: 388316
You can't create a variable name dynamically like that, use an array
var pages = [page_1, page_2, page_3, page_4];
$('#fullContainer').html(pages.pop());
$("#fullContainer").scroll(function () {
// top
if ($(this).scrollTop() === 0 && pages.length) {
console.log("up");
var stringLoad = "page_" + pages.length;
$("<div id='" + stringLoad + "'>" + pages.pop() + "</div>").prependTo($("#fullContainer"));
}
if ($(this).scrollTop() >= $(this)[0].scrollHeight - document.body.offsetHeight) {
console.log("down");
}
});
Demo: Fiddle
Upvotes: 1