mirror of
https://github.com/FAUSheppy/flask-json-dream-website
synced 2025-12-06 08:11:35 +01:00
add lazyload width limitation
This commit is contained in:
@@ -17,7 +17,7 @@ function getSize(src){
|
|||||||
|
|
||||||
/* check if browser is capable of webp */
|
/* check if browser is capable of webp */
|
||||||
function supportsWebp() {
|
function supportsWebp() {
|
||||||
return /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
|
return true;
|
||||||
|
|
||||||
/* alternative to check for webP support */
|
/* alternative to check for webP support */
|
||||||
//if (!self.createImageBitmap) return false;
|
//if (!self.createImageBitmap) return false;
|
||||||
@@ -34,6 +34,8 @@ var counter = 0
|
|||||||
var viewbox_y = -Infinity
|
var viewbox_y = -Infinity
|
||||||
|
|
||||||
IDENT = "realsrc"
|
IDENT = "realsrc"
|
||||||
|
WIDTH_LOCK = "LAZYLOAD_WIDTH"
|
||||||
|
HEIGHT_LOCK = "LAZYLOAD_HEIGHT"
|
||||||
|
|
||||||
/* function to load images */
|
/* function to load images */
|
||||||
function changeSrc(offset){
|
function changeSrc(offset){
|
||||||
@@ -58,6 +60,8 @@ function changeSrc(offset){
|
|||||||
&& boundingClientRect.top < window.innerHeight + offset) {
|
&& boundingClientRect.top < window.innerHeight + offset) {
|
||||||
|
|
||||||
var newSrc = elements[i].getAttribute(IDENT)
|
var newSrc = elements[i].getAttribute(IDENT)
|
||||||
|
var xWidth = elements[i].getAttribute(WIDTH_LOCK)
|
||||||
|
var yHeight = elements[i].getAttribute(HEIGHT_LOCK)
|
||||||
if(!newSrc){
|
if(!newSrc){
|
||||||
console.log(elements[i])
|
console.log(elements[i])
|
||||||
}
|
}
|
||||||
@@ -68,7 +72,17 @@ function changeSrc(offset){
|
|||||||
|| newSrc.indexOf(".png") > -1
|
|| newSrc.indexOf(".png") > -1
|
||||||
|| newSrc.indexOf(".jpeg") > -1){
|
|| newSrc.indexOf(".jpeg") > -1){
|
||||||
/* get correct size */
|
/* get correct size */
|
||||||
|
if(xWidth || yHeight){
|
||||||
|
if(xWidth !=null && xHeight != null){
|
||||||
|
newSrc += "?scalex=" + xWidth + "&scaley=" + yHeight
|
||||||
|
}else if(xWdith != null){
|
||||||
|
newSrc += "?x=" + xWidth
|
||||||
|
}else{
|
||||||
|
newSrc += "?y=" + yHeight
|
||||||
|
}
|
||||||
|
}else{
|
||||||
newSrc += getSize(newSrc)
|
newSrc += getSize(newSrc)
|
||||||
|
}
|
||||||
|
|
||||||
/* load webP if supported */
|
/* load webP if supported */
|
||||||
if(webP){
|
if(webP){
|
||||||
|
|||||||
@@ -164,7 +164,7 @@
|
|||||||
<div class="container text-color-special">
|
<div class="container text-color-special">
|
||||||
<div class="row" {% if loop.index %2 == 1 %} style="flex-direction: row-reverse;" {% endif %}>
|
<div class="row" {% if loop.index %2 == 1 %} style="flex-direction: row-reverse;" {% endif %}>
|
||||||
<div class="mt-3 col image-min-dimensions">
|
<div class="mt-3 col image-min-dimensions">
|
||||||
<img class="img-responsive w-100" realsrc="{{ section['picture'] }}">
|
<img class="img-responsive w-100" realsrc="{{ section['picture'] }}" LAZYLOAD_WIDTH="520">
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-3 col text-min-dimensions">
|
<div class="mt-3 col text-min-dimensions">
|
||||||
<h1>{{ section['title'] }}</h1>
|
<h1>{{ section['title'] }}</h1>
|
||||||
|
|||||||
Reference in New Issue
Block a user