Home Backend Development PHP Tutorial Native ajax waterfall flow demo example sharing

Native ajax waterfall flow demo example sharing

Dec 26, 2017 am 11:13 AM
ajax demo Example

This article mainly brings you a native ajax waterfall flow demo sharing (a must-read article). The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor to take a look, I hope it can help everyone.

It is simply divided into three documents, with detailed comments: img; ajax.php; demo.php

Put the picture 1.jpg; 2.jpg; 3 in the img folder. .jpg....

ajax.php page

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

<?php

  //模拟从数据库读取数据

  $arr = array();

  $op = opendir(&#39;./img&#39;);  //打开目录

 

  //循环读取目录

  while (($file = readdir($op)) !== false) {

    //过滤点和点点

    if ($file == &#39;.&#39; || $file == &#39;..&#39;) {

      continue;

    }

    $arr[] = $file;

  }

  closedir($op);  //关闭目录

  echo json_encode($arr);

Copy after login

demo.html page

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">

  <title>瀑布流</title>

  <style>

    li{

      list-style: none;

      float: left;

      margin:4px;

    }

    img{

      border:4px solid black;

    }

  </style>

</head>

<body>

  <ul id="ul">

    <!-- <li><img src="./img/1.jpg" height="300" alt=""></li> -->

  </ul>

</body>

<script>

  //找对象

  var ul = document.getElementById('ul');

 

  //拿数据

  function getData()

  {

    var ajax = new XMLHttpRequest();

    ajax.open('get''ajax.php', true);

    ajax.send();

    ajax.onreadystatechange = function()

    {

      if (ajax.readyState == 4 && ajax.status == 200) {

        var res = ajax.responseText;

        //处理结果

        var obj = JSON.parse(res);

        for (var k in obj) {

          // obj[k];

          //创建节点

          var li = document.createElement('li');

          li.innerHTML = '<img src="./img/&#39;+obj[k]+&#39;" height="300" />';

          ul.appendChild(li);

        }

      }

    }

  }

  getData();

 

  var timer;

  //判断滚动条的高度,加载第二批文件

  window.onscroll = function()

  {

    //获取三高

    var zGao = document.documentElement.scrollHeight;//总高度

    var lGao = document.documentElement.clientHeight;//浏览器可用高度

    var gGao = document.body.scrollTop || document.documentElement.scrollTop;//滚出去的高度

    // console.log(zGao, lGao, gGao);

 

    document.title = zGao + '_' + lGao + '_' + gGao;

 

    if (zGao - lGao - gGao < 500) {

      clearTimeout(timer);

      //用一次性定时器解决连续加载的问题

      timer = setTimeout(function(){

        getData();

      }, 200)

    }

  }

</script>

</html>

Copy after login

Related recommendations:

JS implementation of waterfall flow layout example analysis

Use JavaScript to create waterfall flow effect

Recommend 5 good-looking jquery waterfall flow effect codes

The above is the detailed content of Native ajax waterfall flow demo example sharing. For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Hot Topics

Java Tutorial
1659
14
PHP Tutorial
1258
29
C# Tutorial
1232
24
What does demo mean? What does demo mean? Feb 12, 2024 pm 09:12 PM

The word demo is no longer unfamiliar to friends who like to sing, but many users who have never been exposed to it are curious about what demo means. Now let’s take a look at the meaning of the demo brought by the editor. What does demo mean? Answer: Demo tape. 1. The pronunciation of demo is ['deməʊ] in English and ['demoʊ] in America. 2. Demo is the abbreviation of "demonstration", which generally refers to the preliminary effect of listening to a song before it is officially recorded. 3. Demo is used as a noun to refer to sample tapes and sample records. The meaning of verb is trial (especially software), demonstration and demonstration;

PHP and Ajax: Building an autocomplete suggestion engine PHP and Ajax: Building an autocomplete suggestion engine Jun 02, 2024 pm 08:39 PM

Build an autocomplete suggestion engine using PHP and Ajax: Server-side script: handles Ajax requests and returns suggestions (autocomplete.php). Client script: Send Ajax request and display suggestions (autocomplete.js). Practical case: Include script in HTML page and specify search-input element identifier.

How to solve the 403 error encountered by jQuery AJAX request How to solve the 403 error encountered by jQuery AJAX request Feb 20, 2024 am 10:07 AM

Title: Methods and code examples to resolve 403 errors in jQuery AJAX requests. The 403 error refers to a request that the server prohibits access to a resource. This error usually occurs because the request lacks permissions or is rejected by the server. When making jQueryAJAX requests, you sometimes encounter this situation. This article will introduce how to solve this problem and provide code examples. Solution: Check permissions: First ensure that the requested URL address is correct and verify that you have sufficient permissions to access the resource.

How to solve jQuery AJAX request 403 error How to solve jQuery AJAX request 403 error Feb 19, 2024 pm 05:55 PM

jQuery is a popular JavaScript library used to simplify client-side development. AJAX is a technology that sends asynchronous requests and interacts with the server without reloading the entire web page. However, when using jQuery to make AJAX requests, you sometimes encounter 403 errors. 403 errors are usually server-denied access errors, possibly due to security policy or permission issues. In this article, we will discuss how to resolve jQueryAJAX request encountering 403 error

How to solve the problem of jQuery AJAX error 403? How to solve the problem of jQuery AJAX error 403? Feb 23, 2024 pm 04:27 PM

How to solve the problem of jQueryAJAX error 403? When developing web applications, jQuery is often used to send asynchronous requests. However, sometimes you may encounter error code 403 when using jQueryAJAX, indicating that access is forbidden by the server. This is usually caused by server-side security settings, but there are ways to work around it. This article will introduce how to solve the problem of jQueryAJAX error 403 and provide specific code examples. 1. to make

How to get variables from PHP method using Ajax? How to get variables from PHP method using Ajax? Mar 09, 2024 pm 05:36 PM

Using Ajax to obtain variables from PHP methods is a common scenario in web development. Through Ajax, the page can be dynamically obtained without refreshing the data. In this article, we will introduce how to use Ajax to get variables from PHP methods, and provide specific code examples. First, we need to write a PHP file to handle the Ajax request and return the required variables. Here is sample code for a simple PHP file getData.php:

Learn best practice examples of pointer conversion in Golang Learn best practice examples of pointer conversion in Golang Feb 24, 2024 pm 03:51 PM

Golang is a powerful and efficient programming language that can be used to develop various applications and services. In Golang, pointers are a very important concept, which can help us operate data more flexibly and efficiently. Pointer conversion refers to the process of pointer operations between different types. This article will use specific examples to learn the best practices of pointer conversion in Golang. 1. Basic concepts In Golang, each variable has an address, and the address is the location of the variable in memory.

PHP vs. Ajax: Solutions for creating dynamically loaded content PHP vs. Ajax: Solutions for creating dynamically loaded content Jun 06, 2024 pm 01:12 PM

Ajax (Asynchronous JavaScript and XML) allows adding dynamic content without reloading the page. Using PHP and Ajax, you can dynamically load a product list: HTML creates a page with a container element, and the Ajax request adds the data to that element after loading it. JavaScript uses Ajax to send a request to the server through XMLHttpRequest to obtain product data in JSON format from the server. PHP uses MySQL to query product data from the database and encode it into JSON format. JavaScript parses the JSON data and displays it in the page container. Clicking the button triggers an Ajax request to load the product list.

See all articles