Pages

Saturday, 27 June 2020

Whatsapp button for website


Add whatsup button at bottom right side of your website. Button will show when user scroll down because it can disturb your home page opening view. When user will click on whatsapp button it will redirect to whatsapp message mode to the given number.

<style>
    /* ========= CSS ==========*/
    .g-whatsapp {
        display: none;
        position: fixed;
        bottom: 20px;
        right: 30px;
        z-index: 99;
        cursor: pointer;
    }
</style>

<!--========= HTML ==========-->
<a href="https://api.whatsapp.com/send?phone=+919119870001" target="_blank">
    <img src="img/page/whatsapp.png" class="g-whatsapp" id="Linkwhatsapp" />
</a>

<script>
    //=========== Java Script ==============
    var mybutton = document.getElementById("Linkwhatsapp");

    // When the user scrolls down 20px from the top of the document, show the button
    window.onscroll = function () { scrollFunction() };

    function scrollFunction() {
        if (document.body.scrollTop > 40 || document.documentElement.scrollTop > 40) {
            mybutton.style.display = "block";
        } else {
            mybutton.style.display = "none";
        }
    }


</script>


No comments:

Post a Comment