From 81d353f875019a5c61d08a10f1616d93b5bdc6d4 Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Sun, 4 Jul 2021 17:21:15 +0200 Subject: [PATCH] LAZYLOAD_WIDTH and LAZYLOAD_HEIGHT attributes --- lazyload.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lazyload.js b/lazyload.js index 88e008e..717825e 100755 --- a/lazyload.js +++ b/lazyload.js @@ -28,6 +28,8 @@ var counter = 0 var viewbox_y = -Infinity IDENT = "realsrc" +WIDTH_LOCK = "LAZYLOAD_WIDTH" +HEIGHT_LOCK = "LAZYLOAD_HEIGHT" /* function to load images */ function changeSrc(offset){ @@ -53,12 +55,26 @@ function changeSrc(offset){ && boundingClientRect.top < window.innerHeight + offset) { var newSrc = elements[i].getAttribute(IDENT) + var xWidth = elements[i].getAttribute(WIDTH_LOCK) + var yHeight = elements[i].getAttribute(HEIGHT_LOCK) + /* remove url( ... ) if it is used */ //newSrc = newSrc.substring(4,newSrc.length-1) if(newSrc.indexOf(".jpg") > -1){ - /* get correct size */ - newSrc += getSize() + + /* determine & set the correct width and height */ + 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) + } /* load webP if supported */ if(webP){