Home Web Front-end JS Tutorial Use jquery to implement scrolling browser scroll bar loading data in asp.net website development (similar to Tencent Weibo)_jquery

Use jquery to implement scrolling browser scroll bar loading data in asp.net website development (similar to Tencent Weibo)_jquery

May 16, 2016 pm 05:55 PM
Browser

I have basically been using Tencent Weibo since it was launched. Until now, as a developer, I have also seen that Tencent Weibo has been constantly changing. I don’t know if you have noticed that Tencent Weibo provides two There are two ways to load data: one is paging, and the other is scrolling the browser scroll bar to load data. I think everyone has done too much of the paging function. Today I will share with you how I use the scroll bar to load data
below Start the lecture:
Let me talk about the idea first. I use Jquery, and then use Jquery’s ajax() method to load remote data through HTTP requests. When using Jquery, you must first apply the jquery.min.js class library. If If it is not available locally, you can also directly quote the following address.
Okay, let’s take a look at the core code:

Copy the code The code is as follows:

// - -!, you know.
var count=<%=allcount %>;
var times=0;
var loaded = true;
function Add_Data()
{
var top = $("#main_left_add").offset().top;
if(loaded && ($(window).scrollTop() $(window).height() > top ))
{
$("#main_left_add").html("Data loading...");
times ;
$.ajax(
{
type: "POST",
dataType: "text",
url: "weibo.ashx",
data: "userid=" <%=hf.Value %> "&touserid=" <% =hf1.Value %> "&count=" count "×=" times "&type=1",
success: function(data)
{
//alert("Append " times " times Data.");
if(data == "No data")
{
$("#main_left_add").css("display","none");
loaded=false ;
AddEffect();
}
else if(data == "")
{
$("#main_left_add").html("Click to load more..." );
$("#main_left_add").css("display","block");
loaded=false;
AddEffect();
}
else if(data ! = "")
{
$("#main_left_down").append(data);
AddEffect();
}
}
}
);
}
}
$(window).scroll(Add_Data);
//Click to add data
$("#main_left_add").click(function(){
$.ajax ({
type: "POST",
dataType: "text",
url: "weibo.ashx",
data:"userid=" <%=hf.Value %> "&touserid=" <%=hf1.Value %> "&count=" count "×=" times "&type=2",
success: function(data){
if(data=="No data")
{
$("#main_left_add").css("display","none");
AddEffect();
}
else
{
$("#main_left_down").append(data);
$("#main_left_add").html("Click to load more...");
AddEffect();
}
}
});
//Mouse movement effect
$("#main_left_add").mouseover(function(){
$(this).css("background-color", "#e4eef8");
});
$("#main_left_add").mouseout(function(){
$(this).css("background-color","#f0f5f8") ;
});

This is the front-end js code. Let me explain the code a little bit: count is the total number of data defined. Two divs are defined. One div is used to append data. A div is used to determine the position of the scroll bar, and a *.ashx file is created to process the program and return the corresponding data. Based on this data, we must determine the loading situation. After the scroll append is completed, I also added an additional "Click to load more" Function...", the implementation of this function is similar to the above...the codes are all above for your reference.
Note: In order to prevent the scroll event from being executed all the time, a loaded is defined to control the execution of the scroll event.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to customize the resize symbol through CSS and make it uniform with the background color? How to customize the resize symbol through CSS and make it uniform with the background color? Apr 05, 2025 pm 02:30 PM

The method of customizing resize symbols in CSS is unified with background colors. In daily development, we often encounter situations where we need to customize user interface details, such as adjusting...

How to correctly display the locally installed 'Jingnan Mai Round Body' on the web page? How to correctly display the locally installed 'Jingnan Mai Round Body' on the web page? Apr 05, 2025 pm 10:33 PM

Using locally installed font files in web pages Recently, I downloaded a free font from the internet and successfully installed it into my system. Now...

Why can custom style sheets take effect on local web pages in Safari but not on Baidu pages? Why can custom style sheets take effect on local web pages in Safari but not on Baidu pages? Apr 05, 2025 pm 05:15 PM

Discussion on using custom stylesheets in Safari Today we will discuss a custom stylesheet application problem for Safari browser. Front-end novice...

How to use locally installed font files on web pages? How to use locally installed font files on web pages? Apr 05, 2025 pm 10:57 PM

How to use locally installed font files on web pages Have you encountered this situation in web page development: you have installed a font on your computer...

Why does negative margins not take effect in some cases? How to solve this problem? Why does negative margins not take effect in some cases? How to solve this problem? Apr 05, 2025 pm 10:18 PM

Why do negative margins not take effect in some cases? During programming, negative margins in CSS (negative...

How to control the top and end of pages in browser printing settings through JavaScript or CSS? How to control the top and end of pages in browser printing settings through JavaScript or CSS? Apr 05, 2025 pm 10:39 PM

How to use JavaScript or CSS to control the top and end of the page in the browser's printing settings. In the browser's printing settings, there is an option to control whether the display is...

The text under Flex layout is omitted but the container is opened? How to solve it? The text under Flex layout is omitted but the container is opened? How to solve it? Apr 05, 2025 pm 11:00 PM

The problem of container opening due to excessive omission of text under Flex layout and solutions are used...

How to use CSS and Flexbox to implement responsive layout of images and text at different screen sizes? How to use CSS and Flexbox to implement responsive layout of images and text at different screen sizes? Apr 05, 2025 pm 06:06 PM

Implementing responsive layouts using CSS When we want to implement layout changes under different screen sizes in web design, CSS...

See all articles