-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex2.html
249 lines (173 loc) · 6.63 KB
/
index2.html
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
119
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script data-require="angular.js@*" data-semver="1.5.0" src="https://code.angularjs.org/1.5.0/angular.js"></script>
</head>
<body ng-app="lazy" ng-controller="AppController">
<div class="flex-container">
<div class="block" ngClass="block" ng-repeat="s in studioImages" lazy-load>
<img class="w-100" ng-src="{{s.imgUrl}}" alt="{{studioName}}" >
</div>
</div>
<style>
.block {
position: absolute;
background: #fff;
padding: 10px;
width: 300px;
border: 1px solid #ddd;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
}
.vertical-center {
min-height: 100%;
min-height: 100vh;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
-moz-box-align: center;
-ms-flex-align: center;
align-items: center;
width: 100%;
-webkit-box-pack: center;
-moz-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
}
.flex-container {
display: flex;
flex-flow: row wrap;
justify-content: flex-start;
}
.img-blur{
filter: blur(10px);
}
</style>
<script>
var app = angular
.module('lazy', [])
.controller("AppController", function( $scope , $http ) {
var colCount =4;
var colWidth = 300; //default
var margin = 20;// default for running heights in image columns
var windowWidth = 0;
var width=300;
//This array is used to store the running heights of each column
$scope.studioImages = [];
$scope.imageHeights = [];
$scope.imageWidths = [];
var blocks = [];
$scope.paramValue = 3;//$stateParams.studioId; //studio 3
var url = "StudioController?action=GALLERY&id="+$scope.paramValue;
console.log(url);
$http({
method: 'GET',
url: url
}).then(function success(response) {
$scope.myWelcome = response.data;
var studioVars=angular.fromJson(response.data);
//lazy load code
var now = ( new Date() ).getTime();
//mine
for(var i =0; i < studioVars.length;i++){
var studioImageObj = {};
studioImageObj.id=studioVars[i].id;
studioImageObj.width = studioVars[i].width;
studioImageObj.height = studioVars[i].height;
studioImageObj.imgUrl = "images/studio"+ $scope.paramValue + "/576/"+studioVars[i].image;
$scope.studioImages.push(studioImageObj);
$scope.imageHeights.push(studioImageObj.height);
$scope.imageWidths.push(studioImageObj.width);
//blocks are for column placement loading
for(var j=0; j<$scope.colCount;j++){
blocks.push(studioImageObj.width);
}
}
$scope.statusval = response.status;
$scope.statustext = response.statusText;
$scope.headers = response.headers();
//$scope.setupBlocks = setupBlocks();
}, function error(response) {
console.log(response.statusText);
});
})
.directive('lazyLoad', lazyLoad)
function lazyLoad(){
return {
restrict: 'A',
link: function(scope, element, attrs){
const observer = new IntersectionObserver(loadImg)
const img = angular.element(element)[0];
var blocks = [];
var colWidth =300;
var margin = 20;
var colCount =4;
var count = 0;
setupBlocks();
//console.log(img);
console.log(scope.studioImages);
observer.observe(img);
function loadImg(changes){
//colcount
changes.forEach(change => {
if(change.intersectionRatio > 0){
//change.target.classList.remove('img-blur');
}
})
}
function setupBlocks() {
windowWidth = $(window).width();
//console.log(windowWidth); //1180
//console.log(colWidth); //300
colCount = Math.floor( windowWidth /( colWidth + margin ) );
//console.log(colCount);//3
for(var i=0; i < colCount; i++) {
//This array is used to store the running heights of each column
blocks.push(20);
}
positionBlocks();
}
function positionBlocks() {
// console.log("positionBlocks");
console.log("in each statement positioning" + colCount + " block " + blocks.length );
count=0;
$('.block').each(function(){
console.log("foundBlock");
var ratio = scope.studioImages[count].width / colWidth;
var min = minArrayVal(blocks);
var colHeight = Math.floor( scope.studioImages[count].height / ratio);
var imgWidth = Math.floor( scope.studioImages[count].width / ratio ) ;
//index number of each value to calculate the position from the left of the screen and top of screen
var index = $.inArray(min, blocks);
console.log("min val: " + min + "outer height: " + colHeight + " index of min val " + index + " image height " + scope.studioImages[count].height);
var leftPos = margin + ( index * ( colWidth + margin ) );
$(this).css({
'left':leftPos+'px',
'top':min+'px'
});
var elm = $(this).children().first().css({ 'width':imgWidth+'px' });
console.log( min + colHeight + margin);
blocks[index] = min + colHeight+margin;
count++;
});
}
function minArrayVal(array) {
return Math.min.apply(Math, array);
};
}
}
}
</script>
</body>
</html>