From e851100bd1ddb883d6f21e59ee1dea2afed55291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Pilay=20Mu=C3=B1oz?= Date: Tue, 20 Oct 2020 03:43:18 -0500 Subject: [PATCH] pornhub case study (images hover preview) hacktoberfest --- .DS_Store | Bin 0 -> 6148 bytes example/showcase.html | 10 +++++----- src/hover-preview.js | 44 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b73ff0064019fee863f2c647a3830598fc9cd852 GIT binary patch literal 6148 zcmeHKOG-mQ5Ue%<18%Z(IalxoLx?BH1rjj0iBSZ_QQxcg^&4 z&EwVL^=kmO_;`8%<^X1NM;tti&ClIOc2gN6(s{=lcG!Nd-uJuLQT6$Rb8oT57dCkL z&EG%gt>U!ajm~>bTA68GcnoumB&ih-G!+N5k6p#X^ z3QTf4_x}G#zcBxwlC+ZoQs7@HVAJJlx!@~RZymjy_u58Z)4k@K?#6Xc7@{2$qaAbO f?f5>5vab1>=e=-93_9~cC+cUwb&*MdzgFM}lnE7} literal 0 HcmV?d00001 diff --git a/example/showcase.html b/example/showcase.html index 05aac07..1df0fd3 100644 --- a/example/showcase.html +++ b/example/showcase.html @@ -29,9 +29,9 @@
-
+
- Use is as a preview of a gallery
-
+

Or as a preview for a video

@@ -63,9 +63,9 @@

Or as a preview for a video

-
+
- { img.addEventListener('mouseenter', mouseEnterListener) }) + + + const almover = () => { + let last_known_scroll_position = window.scrollY; + images.forEach(img => { + + if((last_known_scroll_position >= (parseInt(img.dataset.posy) - 10)) && (last_known_scroll_position <= (parseInt(img.dataset.posy) + 10))) + { + + hoveredImg.el = img + hoveredImg.poster = hoveredImg.el.getAttribute('src') + hoveredImg.index = -1 + hoveredImg.images = hoveredImg.el.getAttribute('data-preview').split('|') + + timeout.set(() => previewImages(true), HOVER_DELAY) + hoveredImg.el.addEventListener('mouseleave', () => { + hoveredImg.reset() + timeout.reset() + }) + + //console.log(img.id); + //mouseEnterListener(img); + //console.log(`${img.id}, img position :${img.dataset.posy} , scroll positions: ${last_known_scroll_position}`); + } + }) + } + + const setPosYImages = () => { + images.forEach(img => { + img.dataset.posy = img.getBoundingClientRect().y; + }) + } + + window.addEventListener('scroll', function(){ + almover(); + }) + + window.addEventListener('load', function(){ + setPosYImages(); + }) + + })()