Avalonjs make response waterfall flow effect

Source: Internet
Author: User
Tags json min

Waterfall flow is mainly used in the picture Display page. If there are a large number of pictures need to show, the original picture size is inconsistent, and hope that each picture can not cut, complete display, then give the picture to set a width, to liberate their height. Use the page height not limited to this feature, make full use of the space of the page, as much as possible to display more pictures. Let's go into the details below.

Layout is not based on float, also not based on absolute positioning, see the bottom of the html,css know. No more annoying HTML inserts, and the code is refreshing.

?

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 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 72 73 74 75 76 77 78 79 80 81 82 83 5, 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 11 9 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148-149 function GetIndex (index) {if (Index <) {index = "+" + Index;} else if (Index <) {index = "0" + Index;} return index; var $ = function (ID) {return document.getElementById (ID);}; Require (["avalon-min"], function (Avalon) {var waterfall = {load_items:null, loaded_items:[], col_num:0,//number of columns water Fall_model:null, col_width:200, loaded_num:0, init_num:0, Loading:false, start:0, Resizing:false, Find_shortest_ Col:function () {///Find the minimum height column var a = Avalon ($ (' row0 ')). Height (), min_i = 0; for (var i = 1; i < This.col_num; i++) { var B = Avalon ($ (' row ' + i)). Height (); if (b < a) {min_i = i; a = b;}} return min_i; }, Init:function (data) {this.load_items = data; this.loaded_items=this.loaded_items.concat (data); This.waterfall_ model = Waterfall_model; This.col_num = Math.floor (Avalon (Window). Width ()/this.col_width); This.init_num = This.col_num; for (var j = 0; J < This.col_num; J +) {Waterfall_model.img_list.push ([]);} for (var j = 0; J &Lt This.col_num; J + +) {//The first line of the picture Var a={}; A.src=getindex (data[j].src); a.height=data[j].height; a.text=data[j].text; Waterfall_ Model.img_list[j].push (a); } This.start=this.col_num; }, Add_item:function (i) {var a = This.find_shortest_col (); var b={}; var c=this.load_items[this.init_num+i]; if (c) {B.S Rc=getindex (C.SRC); B.height=c.height; B.text=c.text; Waterfall_model.img_list[a].push (b); }, Resize_item:function (i) {//console.log (i); var a = This.find_shortest_col (); var b={}; var c=this.loaded_items[this. Init_num+i]; if (c) {b.src=getindex (C.SRC); b.height=c.height; b.text=c.text; Waterfall_model.img_list[a].push (b);}} }; var Waterfall_model = avalon.define ("Waterfall", function (VM) {//VM vm.img_list = []; vm.rendered = function () {//per picture load shading After dye execution   if (waterfall.resizing) {if (waterfall.loaded_num+ waterfall.init_num<waterfall.loaded_items.length) { waterfall.loaded_num++; Waterfall.resize_item (Waterfall.loaded_num); waterfall.start++; }}else{  if (waterfall.loadEd_num + waterfall.init_num <waterfall.load_items.length) {waterfall.loaded_num++; Waterfall.add_item ( Waterfall.loaded_num); waterfall.start++; } } }; }); Avalon.config ({debug:false}); Avalon.scan (); function Debouncer (func, timeout) {var timeoutid, timeout = timeout | |; return function () {var scope = this, a RGS = arguments; Cleartimeout (Timeoutid); Timeoutid = settimeout (function () {func.apply (scope, Array.prototype.slice.call (args));}, timeout); } avalon.post ("Http://localhost/css/test.php?start=0", function (data) {//Load First waterfall.init (data);}, "JSON"); Window.onscroll =debouncer (function (e) {var scrolltop = Avalon (Window). scrolltop (), WindowHeight = Avalon (window). He Ight (), documentheight = Avalon (document). Height (); if (WindowHeight + scrolltop==documentheight) {avalon.post ("http://localhost/css/test.php?start=" + (Waterfall.start ), function (data) {//Load first waterfall.resizing=false; waterfall.load_items=data; Waterfall.loaded_items=waterfaLl.loaded_items.concat (data); Waterfall.loaded_num =waterfall.init_num=0; Waterfall.add_item (0); }, "JSON"); } }); Window.onresize = Debouncer (function (e) {var windowwidth = Avalon (Window). Width (), k = Math. Floor (windowwidth/200) , Detect_left = Avalon ($ (' Waterfalldetect ')). Offset (). Left; if (Math.Abs (detect_left) >= 199) {waterfall.col_num = Math.floor (Avalon (Window). Width ()/waterfall.col_width); Waterfall_model.img_list = []; for (var j = 0; J < Waterfall.col_num; J + +) {Waterfall_model.img_list.push ([]);} waterfall.resizing=true; Waterfall.loaded_num =waterfall.init_num=0; waterfall.start=0; Waterfall.resize_item (0); }},30); });

Html

?

1 2 3 4 5 6 7 8 9 10 11 12-13 <div id= ' wrap ' ms-controller= "Waterfall" > <ul ms-each-els= "img_list" id= ' Wrap_row ' > <li ms-each-el= ' Els "Ms-attr-id= ' row{{$index}} ' data-each-rendered= ' rendered ' > <p> <span>{{el.src}}</span > </p> </li> <li id= ' waterfalldetect ' ms-if= ' $last ' ></li> </ul> </div>

Css

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20-21 #wrap ul li {display:inline-block; *display:inline; zoom:1 vertical-align:top; font-size:16px;} #wrap ul Li p {ma rgin:5px 2.5px; border:1px solid red; min-width:192px; min-height:100px; #wrap span {Display:block} #waterFallDetect {width:192px; height:100px; border:1px solid Red;}

The above mentioned is the entire content of this article, I hope you can enjoy.

Note : For more wonderful tutorials, please pay attention to the triple graphics tutorial channel,

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.