1. Tutorial : https://www.youtube.com/watch?v=3H9qLDenr7k
  2. CSS
  3. -------
  4. /* box container */
  5. .website-box {
  6. height: 300px;
  7. overflow: hidden;
  8. }
  9.  
  10.  
  11. /* website image position */
  12. .website-img img{
  13. object-fit: contain;
  14. object-position: 0px 0px;
  15. transition: object-position 6s ease;
  16. }
  17.  
  18.  
  19.  
  20.  
  21.  
  22. JS
  23. ------
  24. <script>
  25. var imgBox = document.querySelectorAll('.website-img img');
  26. for(i=0; i<imgBox.length;i++){
  27. imgBox[i].addEventListener('mouseenter', function(hover){
  28. var imgHeight = this.scrollHeight;
  29. var scrollheight = imgHeight - 300;
  30. hover.target.style.objectPosition = `0px -${scrollheight}px`;
  31.  
  32. });
  33.  
  34. imgBox[i].addEventListener('mouseleave', function(hover){
  35. hover.target.style.objectPosition = '0px 0px';
  36.  
  37.  
  38. });
  39. }
  40.  
  41. </script>
  42.  
  43.  
  44. --------------
  45. Image Class: website-img
  46. Column Class: website-box

Leave a Comment