Scroll and Zoom effect in CSS

For basic styles adding bootstrap UI cdn.

And for DOM manipulation, adding jquery cdn in the header of html document.

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">


<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.slim.min.js"></script>

Adding main image

Adding some high quality image from google search results.

  <div class="header" id="parallex">
    <img class="header-image" src="https://handluggageonly.co.uk/wp-content/uploads/2015/12/London-1.jpg" alt="">
  </div>

Adding some random content

Adding some lorem ipsum content to make the page looks longer. So that we can scroll and see the effect.

<p class="container">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Recusandae similique perferendis quaerat porro, facilis quidem itaque qui excepturi autem ab iure ea quae vero dolorum fugiat alias accusantium, unde laborum facere pariatur soluta quibusdam
    numquam! Rerum iure similique, magnam tempore voluptatem molestias adipisci velit eaque ipsam eum sed consequatur ducimus magni enim cumque! Modi quia quibusdam praesentium ab quis quasi magni enim velit, rem numquam accusantium expedita labore suscipit.
    Dolores repellendus itaque, facere aliquid at nihil obcaecati voluptatibus laborum excepturi sapiente molestiae eius non sequi architecto delectus, repellat, iste ducimus iusto cum. Fuga animi soluta dolorem, ratione dolorum repellat voluptatum eaque
    esse aperiam impedit ex, blanditiis dignissimos ab nostrum. Quo adipisci nostrum repellat accusamus voluptatibus eius error sed! Architecto sed ut obcaecati porro ipsum alias eos at neque quae, veritatis, soluta! Harum tenetur quae maxime laborum
    ipsum nostrum laudantium repellendus quas cum adipisci est maiores, tempore tempora enim autem consequatur qui aperiam. Explicabo odit dolorem, assumenda veritatis dolor rerum maiores nobis impedit delectus eos quidem alias necessitatibus hic repellat
    aut a obcaecati, ullam distinctio, nisi, dolore facere tenetur. Illo sequi ab consequuntur et corrupti id dicta impedit qui quo, quasi sapiente cumque nulla adipisci ipsum voluptatem est atque architecto voluptas recusandae accusantium. Accusamus
    cupiditate, doloremque quae magni. Earum enim, quidem eveniet expedita! Labore aliquam, animi cum architecto repellendus possimus eos temporibus vitae sapiente optio dolorum dolorem qui alias, ratione quas voluptatibus incidunt recusandae amet praesentium
    accusantium enim esse sit magnam. Tempore iure, facilis placeat ipsa, laborum mollitia. Ipsam quos nostrum temporibus ex ipsum velit dignissimos maiores, facere, architecto dolorem mollitia repellendus necessitatibus officia accusantium expedita assumenda
    ipsa laborum nesciunt quam numquam consectetur. Id vero impedit, assumenda architecto eaque laborum deserunt commodi laboriosam itaque adipisci, omnis aperiam. Nostrum obcaecati est, dicta numquam ea cumque nemo sint, maiores mollitia hic. Quod at
    fugit iste. Obcaecati debitis quos facere delectus nemo beatae numquam. Vero excepturi obcaecati amet, consequatur velit eveniet sunt optio sint consequuntur alias eligendi voluptas voluptates, facere? Consequuntur corrupti a quis, enim? Officiis
    ea incidunt consequatur maiores, esse reiciendis magni, distinctio aut neque facere odio eius dicta natus provident consequuntur voluptatum ducimus tenetur, totam dolorum corporis animi expedita repellat! Dolorem inventore molestias aliquid, distinctio
    libero quisquam, facere iste earum delectus assumenda, quis nobis totam unde vero nostrum quas corrupti! Adipisci omnis sequi nemo odio iusto cupiditate dolorum voluptatibus nesciunt pariatur amet ipsam dignissimos eum facilis est iste ea delectus,
    itaque eius! Reiciendis facilis voluptas, expedita optio. Ducimus omnis facere illo commodi ut sequi veritatis quae nam et quasi delectus similique, ex voluptatibus odio recusandae officia consectetur voluptate nesciunt qui soluta ipsam. Aliquid rerum
    accusamus esse suscipit error nihil maxime sequi, illo illum aspernatur officiis ad, culpa dignissimos ratione, veniam. Ea dolore aperiam, qui. Sit aspernatur repudiandae atque rerum accusamus eum quos illum aliquid mollitia quis ratione pariatur
    praesentium totam beatae labore expedita, quidem provident hic veritatis officia corrupti magni facilis dolor incidunt voluptatibus! Obcaecati incidunt aspernatur corporis asperiores quaerat iste, ratione necessitatibus quibusdam ipsa nobis accusamus
    laborum est, rerum similique sapiente.</p>

So far we have added the HTML content. Lets add some CSS magic.

CSS magic

body: {
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

img {
  width: 100%;
}

.header {
  height: 500px;
  overflow: hidden;
}

p {
  font-family: tahoma;
  font-size: 20px;
  padding: 50px;
}

Basically, this CSS sets the document height and width, and keeping the image stretch to 100%.

So far we have added some HTML text content and image in header. To add some scroll and zoom effect, lets add some javascript/jQuery code.

jQuery code

$(window).scroll(function() {
  var scroll = $(window).scrollTop();
  console.log(scroll);
  $("#parallex img").css({
    width: 100 + scroll / 5 + "%"
  });
});

The above code, adds the width of image based on the windows scroll position.

Final Output

You can checkout the final output in the below codepen.

Thanks for reading. Please share your feedback in comment section below.

Baffle effect

Welcome to another CSS post. In this post, we will discuss on how we can add baffle effect to a text in HTML document using library.

Baffle.js is a tiny JavaScript library for obfuscating and revealing text in DOM elements.

Installation

Add the library from CDN in the top of HTML document.

<script src="<https://cdn.jsdelivr.net/npm/baffle@0.3.6/dist/baffle.min.js>"></script>

Add text

Lets create a paragraph element to show some text which we are going to use to add effect later.

<p class="effect">
    Hello, world..
</p>

Some CSS magic

Here is some CSS magic to add in our document to have some decent look. Basically just aligning the content to center.

body {
    width: 90%;
    height: 90vh;
    background-color: pink;
    display: flex;
    justify-content: center;
    align-items: center;
}

.effect {
    font-family: 'tahoma';
    font-weight: 800;
    font-size: 58px;
}

Baffle configuration

Lets, add the baffle js configuration to apply the effect at the end of document with the help of script tag.

<script>
    // With a CSS selector
    const b = baffle('.effect');
    b.set({
        character: '>▓▒ /█▒</ >▒░>▒ █<░ ░█▒░> ▓░/▒ ▒>░ █<▒▓ ▓▒>░',
        speed: 120
    });

    // Start obfuscating
    b.start();
    
    // Reveal text
    b.reveal(5000);
    
    // Stop obfuscating
    b.stop();

</script>

Here, we have passed the CSS selector which targets the text that needs to obfuscated.

With baffle instantiated, you can start your instance with the start() method, stop it with stop(), or reveal it with reveal().

That’s it, we are done. We can see the changes in the browser.

Happy Coding!

Full Demo:

To get latest updates you can follow or subscribe! #peace