Last active
December 14, 2015 06:49
-
-
Save hustlzp/5045613 to your computer and use it in GitHub Desktop.
Code for waterfall of images.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// html code | |
<div class="products-wap clearfix"> | |
{% for product in products %} | |
<div class="product-item"> | |
<a href="{{ url_for('single_product', product_id=product.ProductID)}}"> | |
<img class="product-image" title="{{ product.Product }}" src="{{ product.ImageUrl }}"> | |
</a> | |
</div> | |
{% endfor %} | |
</div> | |
// https://github.com/desandro/imagesloaded | |
<script type="text/javascript" src="{{ url_for('static', filename='js/jquery.imagesloaded.js') }}"></script> | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
var width = 290, | |
h_gap = 20, | |
v_gap = 22; | |
var lefts = [0, width+h_gap, 2*(width+h_gap)], | |
tops = [0, 0, 0]; | |
$('.product-image').each(function(index){ | |
$(this).css({ | |
'width': width + 'px', | |
'left': lefts[index%3] + 'px' | |
}); | |
}); | |
$('.product-image').each(function(index){ | |
// only when a img loaded, it's height becomes known. | |
$(this).imagesLoaded(function(){ | |
$(this).css({ | |
'display': 'block', | |
'top': tops[index%3] + 'px' | |
}); | |
// overadd height | |
tops[index%3] += $(this).height() + v_gap; | |
// set mother wap's height | |
var maxHeight = 0; | |
for(var i=0; i<tops.length; i++){ | |
if(tops[i] > maxHeight){ | |
maxHeight = tops[i]; | |
} | |
} | |
$('.products-wap').css('height', maxHeight + 'px'); | |
}); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.products-wap{ | |
position: relative; | |
.product-item{ | |
.product-image{ | |
opacity: 0.9; | |
display: none; | |
position: absolute; | |
&:hover{ | |
opacity: 1; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment