Jquery code implements simple random image waterfall stream Effects

Source: Internet
Author: User

Jquery code implements simple random image waterfall stream Effects

Jquery code implements simple random image waterfall stream Effects

Waterfall flow layout has been very popular recently. Many people want to know how to make it like me, I have finally written a large number of online searches for references and N-edge experiments. I will share them with you here for your reference.

To make it easier for everyone to understand how jQuery is used. Of course, it is more efficient to execute js code from the source, but many people are not very skilled at js from the source.

Code:

?

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

<Html xmlns = "http://www.w3.org/1999/xhtml">

<Head>

<Title> infinite loading of jquery random image waterfall stream </title>

<Style type = "text/css">

* {Margin: 0; padding: 0; list-style-type: none ;}

A, img {border: 0 ;}

Body {font: 12px/180% Arial, Helvetica, sans-serif, "";}

/* Container */

# Container {width: 940px; margin: 50px auto ;}

# Container ul {width: 300px; list-style: none; float: left; margin-right: 20px ;}

# Container ul li {margin-bottom: 20px ;}

# Container ul li img {width: 300px ;}

</Style>

</Head>

<Body>

<Div id = "container">

<Ul class = "col">

<Li> </li>

<Li> </li>

<Li> </li>

</Ul>

<Ul class = "col"> </ul>

<Ul class = "col" style = "margin-right: 0"> </ul>

</Div>

<Script type = "text/javascript" src = "/ajaxjs/jquery-1.9.1.min.js"> </script>

<Script type = "text/javascript">

$ (Function (){

Function loadMeinv (){

Var data = 0;

For (var I = 0; I <9; I ++) {// simulate random image loading at each loading

Data = parseInt (Math. random () * 9 );

Var html = "";

Html = '<li>

Using data='.jpg> <p> src ='

Using data='.jpg </p> </li> ';

$ MinUl = getMinUl ();

$ MinUl. append (html );

}

}

LoadMeinv ();

$ (Window). on ("scroll", function (){

$ MinUl = getMinUl ();

If ($ minUl. height () <= $ (window). scrollTop () + $ (window). height ()){

// Load the new image when the shortest ul height is greater than the window height + the browser height

LoadMeinv ();

}

})

Function getMinUl () {// obtain the shortest ul every time and put the image behind it

Var $ arrUl = $ ("# container. col ");

Var $ minUl = $ arrUl. eq (0 );

$ ArrUl. each (function (index, elem ){

If ($ (elem). height () <$ minUl. height ()){

$ MinUl = $ (elem );

}

});

Return $ minUl;

}

})

</Script>

<Div style = "text-align: center; margin: 50px 0; font: normal 14px/24px 'Microsoft yahei';">

</Div>

<Div> http://www.jb51.net/</div>

</Body>

</Html>

The above is all the content of this article. I hope you will like it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.