Add Slide in on Scroll Animation on Blogger Blogspot Post Images




    Live Demo

    Sliding in Images on Scrolling the page a tiny but very stylish animated effect we see on any blog. We have used pure JavaScript not any frame-work there will be no compatibility issues in modern browsers. 

    Slide in on Scroll Animation Description:

    What the script does is it will not hide the images but it will change the opacity of the image to 0 and we have used the CSS3 Translate property to move the images left side so that we see the Slide effect on Scroll. 

    This means the image will be on the page but it will not show as the opacity is 0 and when users scroll the page and as soon as the user reached the image the image will slide in and appear to the user and when users are not viewing the image again will disappear or slide out with opacity 0.

    This Type of Animation Effects for some users can be irritating so for a blog a better user interface is important and this animation is done using JavaScript if in any browser JavaScript is disabled then this Slide in animation will not run.

    Now We have informed you about all the advantages and disadvantages now its time to add it in our blogs.

    Adding the Script in Template:

    STEP 1:  Go To Template Section As Shown in The Image Below
    Template

    STEP 2:  Now Search for (Search by Pressing CTRL + F) 

     </body>

    You Will Find This Code 3 Times or more in your Template So Refer 2nd or 3rd Time.

    STEP 3:  Copy This Below Code Before </body>
    <b:if cond='data:blog.pageType == &quot;item&quot;'>
    <style>
    .post-body img {      opacity:0;      transition:all .5s;    }
        .post-body img {      transform:translateX(-50%) scale(0.95);    }
        .post-body .active {      opacity:1;      transform:translateX(0%) scale(1);    }
    </style>
    <script>
    //<![CDATA[
     function debounce(func, wait = 20, immediate = true) {      var timeout;      return function() {        var context = this, args = arguments;        var later = function() {          timeout = null;          if (!immediate) func.apply(context, args);        };        var callNow = immediate && !timeout;        clearTimeout(timeout);        timeout = setTimeout(later, wait);        if (callNow) func.apply(context, args);      };    }         var post = document.querySelector(".post-body");   var sliderImages = post.querySelectorAll("img");
        function checkSlide() {      sliderImages.forEach(sliderImage => {        const slideInAt = (window.scrollY + window.innerHeight) - sliderImage.height / 2;        const imageBottom = sliderImage.offsetTop + sliderImage.height + 100;        const isHalfShown = slideInAt > sliderImage.offsetTop;        const isNotScrolledPast = window.scrollY < imageBottom;        if (isHalfShown && isNotScrolledPast) {          sliderImage.classList.add('active');        } else {          sliderImage.classList.remove('active');        }      });    }
     window.addEventListener("scroll", debounce(checkSlide));                 //]]>  </script></b:if>

    STEP 4:  All done save the template and Open Your Post and Scroll Down Half The Way To See This Widget Working.


    Customization:

    • If you want to Show the images always once you scroll through them then delete the else Condition Highlighted in the Yellow Color.

    Conclusion:


    By default the script will only load and run in posts pages not in homepage or index page so if you want this slide in effect for homepage not in post pages then please inform us in comments.


    That's It Thanks For Following our Tutorial '' Add Slide in on Scroll Animation on Blogger Blogspot Post Images '' Along With us If you found any difficulty Please Comment and Share Your Valuable Opinion. And Stay tuned for More Tutorials Like This and Share this with your friends.

    No comments:

    Post a Comment