Hi all ,
I am making a scroll feature in my website that loads more items into the datalist when i scroll down (like Facebook)
Code :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="temp_Test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style>
.AlbumShadow
{
float: left;
margin-top: 8px;
margin-left: 20px;
background: #aaa;
}
.AlbumShadow img
{
margin: -4px 4px 4px -4px;
display: block;
position: relative;
padding: 4px;
border-left: 1px solid #ccc;
border-top: 1px solid #ccc;
border-right: 1px solid #888;
border-bottom: 1px solid #888;
background: #fcfcfc;
}
</style>
<script src="../jscripts/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
function lastPostFunc() {
$('#divPostsLoader').html('<img src="images/loading.gif">');
//send a query to server side to present new content
$.ajax({
type: "POST",
url: "test.aspx/ItemsGet",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if (data != "") {
document.getElementById('divLoadData').innerHTML = document.getElementById('divLoadData').innerHTML + data.d;
$('.divLoadData:last').after(data.d);
}
$('#divPostsLoader').empty();
}
})
};
//When scroll down, the scroller is at the bottom with the function below and fire the lastPostFunc function
$(window).scroll(function () {
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
lastPostFunc();
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<div id="divPostsLoader">
</div>
<div id="divLoadData">
</div>
</div>
</form>
</body>
</html>
I am making a scroll feature in my website that loads more items into the datalist when i scroll down (like Facebook)
Code :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="temp_Test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style>
.AlbumShadow
{
float: left;
margin-top: 8px;
margin-left: 20px;
background: #aaa;
}
.AlbumShadow img
{
margin: -4px 4px 4px -4px;
display: block;
position: relative;
padding: 4px;
border-left: 1px solid #ccc;
border-top: 1px solid #ccc;
border-right: 1px solid #888;
border-bottom: 1px solid #888;
background: #fcfcfc;
}
</style>
<script src="../jscripts/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
function lastPostFunc() {
$('#divPostsLoader').html('<img src="images/loading.gif">');
//send a query to server side to present new content
$.ajax({
type: "POST",
url: "test.aspx/ItemsGet",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if (data != "") {
document.getElementById('divLoadData').innerHTML = document.getElementById('divLoadData').innerHTML + data.d;
$('.divLoadData:last').after(data.d);
}
$('#divPostsLoader').empty();
}
})
};
//When scroll down, the scroller is at the bottom with the function below and fire the lastPostFunc function
$(window).scroll(function () {
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
lastPostFunc();
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<div id="divPostsLoader">
</div>
<div id="divLoadData">
</div>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class temp_Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethod]
public static string ItemsGet()
{
return "<div class='AlbumShadow'><img src='../NewImages/ME0224f.jpg' width='100px' height='100px'/></div>";
}
}
Comments
Post a Comment