CSS Techniques

CSS Techniques ”; Previous Next For a web developer, when it comes to creating a parallax scrolling effect, various techniques are available. One of such techniques is using Cascaded Styling Sheets(CSS). CSS explains how the HTML elements are displayed on the screen. One can create a CSS file and it can be used for the complete website. It is simpler to add CSS file than adding styles to each HTML element and manage them in different parts of the web page. Note − Some of the methods discussed below in this chapter are specific to desktop computers and not for mobile devices. It will be mentioned in the steps when a particular technique is not suitable for mobile devices. Considering CSS offloads into all the extra drawing into the document object model (DOM), there is a greater utilization of hardware acceleration and a smooth effect without burdening the CPU. Absolute Position Method This method is frequently used to create a parallax effect, as this is relatively light in weight compared to other options available. The position of the background image is kept fixed as relative to other content on the screen. In the example discussed below, you will see how to do it using the magic of CSS. In this section, we will go through two methods for Absolute Position Method − Single Background Multiple Background Single Background Method In this method, we will create two files in the same folder. Observe the steps given below for the same purpose − Step 1 We have to create two files in the same folder: first file with HTML markup and the second with CSS code. Step 2 Now, let us define our HTML markup. Observe the code given below − <html> <head> <link rel = “stylesheet” href = “styles.css”> </head> <body> <div class = “BgContainer”> <div class = “Parallax”> <h1> Welcome! </h1> </div> <div class = “FgContainer”> <div class = “MainContent”> <p> Here we will go ahead with some content which will really vary according to the content on your site. I am just typing out this content as it is sometimes good to engage user than the usual lorem ipsum text! <br/> <br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/> <br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </p> </div> </div> </div> </body> </html> Step 3 Open notepad. Copy and paste the above code snippet. When you are saving the file, under Save as type, select All Files. Enter a name to your file as required, but it needs to be followed by an extension − .html as shown in the screenshot below. Step 4 Once the file is saved, create another file in notepad and paste the code given below − html, body { font-size: 18px; line-height: 28px; } h1 { letter-spacing: -15px; color: white; text-align: center; font-size: 200px; font-weight: 800; line-height: 200px; } BgContainer { perspective: 1px; transform-style: preserve-3d; height: 100vh; overflow-x: hidden; overflow-y: scroll; } FgContainer { position: relative; display: block; background-color: white; z-index: 1; } MainContent { max-width: 750px; margin: 0 auto; padding: 75px 0; } p { margin: 75px 0; } .Parallax { display: flex; flex: 1 0 auto; position: relative; z-index: -1; height: 100vh; justify-content: center; align-items: center; transform: translateZ(-1px) scale(2); background: url(https://cdn.pixabay.com/photo/2017/02/07/09/02/background-2045380_640.jpg); background-color: rgb(250,228, 216); } As you have seen in the last step, when you are saving the file, under Save as type, select All Files. Enter a name to your file as required and add an extension .css to it. Analysis of Code Let us understand which part of the code is responsible for the parallax effect. Most important work for parallax is done by using perspective and transform rules. Refer to line 15 in the above code snippet. The perspective is created for our BgContainer first. This initiates a platform for transform rule. In the Parallax container starting on line 40, transform rule on line 48 pushes the BgContainer div into background using translate(-1px). You can modify the values for translate and scale parameters to modify the depth of the parallax. When you open the html file, the parallax effect will be visible as shown below − Note − For the rest of the tutorial, it will be assumed that the reader is able to create the HTML and CSS files as per the folder structure provided in above method. Multiple Background Method In this method, we will have different images coming across as the user scrolls down the page. There is an image with pencils, which is used in different color combinations to illustrate this effect. Observe the following code for HTML page as shown below − <html> <head> <link rel = “stylesheet” href = “styles.css”> </head> <body> <h1>Multiple Background Example</h1> <div class = “parallax”> <div class = “bg__First”>First</div> <div class = “bg__Second”>Second</div> <div class = “bg__Third”>Third</div> <div class = “bg__Fourth”>Fourth</div> </div> </body> </html> Similar to the previous example, we will use styles.css stored on the same location as this HTML file. We have three different div named as First, Second, Third and Fourth. The CSS code for the parallax scrolling is given below − body, html { height : 100%; font-family : sans-serif; } .parallax [class*=”bg__”] { position : relative; height : 50vh; text-indent : -9999px; background-attachment : fixed;

jQuery Techniques

jQuery Techniques ”; Previous Next In the previous chapters, we have understood how using JavaScript libraries adds good effects to websites. JavaScript, when coupled with jQuery, provides phenomenal flexibility and ease to add parallax scrolling to your websites. In this chapter, we are going to look at three jQuery plugins to add the parallax scrolling effect. Just like how we referenced in the previous chapter for JavaScript, we are going to use jQuery references in our HTML code to create powerful jQuery parallax scrolling. An important point to note about jQuery plugins is that often the plugins are not updated, hence you would want to do some research before you start using any plugin for parallax scrolling. Simple Parallax Scrolling using Parallax.js Using Parallax.js jQuery plugin, we can create parallax scrolling effect without much hassles. Considering jQuery plugin requires a high-end inclusion of libraries such as bootstrap. Note that in this chapter will have HTML5 tags in the code. Let us look at the HTML file shown below − <!DOCTYPE html> <html lang = “en”> <head> <title>Parallax.js | Simple Parallax Scrolling Effect with jQuery</title> <meta charset = “utf-8”> <meta http-equiv = “X-UA-Compatible” content = “IE = edge”> <meta name = “viewport” content = “width = device-width, initial-scale = 1”> <link href = “css/bootstrap.min.css” rel = “stylesheet”> <link href = “css/style.css” rel = “stylesheet”> <script src = “https://code.jquery.com/jquery-1.12.4.min.js”></script> <script src = “https://cdn.jsdelivr.net/parallax.js/1.4.2/parallax.min.js”></script> </head> <body> <section> <div class = “container”> <h1>Example on Parallax.js</h1> <p data-pg-collapsed> This is an example of parallax scrolling using Parallax.js jQuery Plugin. </p> <br/> </div> </section> <div class = “parallax-container” data-parallax = “scroll” data-position = “top” data-bleed = “10” data-image-src = “https://pixabay.com/get/ea31b90a2af5093ed1534705fb0938c9bd22ffd41cb2114595f9c67dae/clematis-3485218_1920.jpg” data-natural-width = “1600” data-natural-height = “800” > </div> <section> <div class = “container”> <h2 id = “sampleLorem”>Sample Text Here</h2> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. <br/> <br/> Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. <br/> <br/> Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. <br/> <br/> Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet mauris. Morbi in dui quis est pulvinar ullamcorper. <br/> <br/> Nulla facilisi. Integer lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. Aenean laoreet. Vestibulum nisi lectus, commodo ac, facilisis ac, ultricies eu, pede. Ut orci risus, accumsan porttitor, cursus quis, aliquet eget, justo. Sed pretium blandit orci. <br/> <br/> Ut eu diam at pede suscipit sodales. Aenean lectus elit, fermentum non, convallis id, sagittis at, neque. Nullam mauris orci, aliquet et, iaculis et, viverra vitae, ligula. Nulla ut felis in purus aliquam imperdiet. Maecenas aliquet mollis lectus. Vivamus consectetuer risus et tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. <br/> <br/> </p> </div> </section> <div class = “parallax-container” data-parallax = “scroll” data-bleed = “10” data-speed = “0.2” data-image-src = “https://pixabay.com/get/ea31b90620f0063ed1534705fb0938c9bd22ffd41cb2114594f0c37cae/chamomile-3489847_1920.jpg” data-natural-width = “1600” data-natural-height = “801” data-pg-name = “PARALLAX IMAGE 002”> </div> </body> </html> Analysis of Code The above code snippets show the code for a page with two images and a sample text between them. As you can see, the code starts with <!DOCTYPE html>, this is typical way of letting the browsers know that the code is HTML5 based. The <meta> tags from line 4 to 6 shows the code which is for machine interpretation. You will not be able to see the impact of this code. Important thing to note here is – with meta tag, web developers get an enhanced control over the data being displayed. Also, on line 8 and 9, we have included the CSS stylesheets along with Bootstrap. For a specific font face and typography, Bootstrap is the widely used library. Lines 10 and 11 take care of the jQuery and Parallax.js libraries. It is important to include Parallax.js for having the control over parallax effect of images. You will be able to find data-parallax property with div on line 21, which is sufficient enough to call parallax.js library for the required parallax effect. Parallax effect can be seen in code on lines 21 and line 40. Important properties which make this effect happen with parallax.js are – data-parallax, data-image-src, data-natural-width, data-natural-height. With the CSS file, we have only one property to provide. It is as shown below − .parallax-container { height: 500px; width: 100%; } In the HTML code above, we have created a specific structure for CSS files. We will have a folder called css, which

Discussion

Discuss Parallax Scrolling in Web Design ”; Previous Next This tutorial aims to make you acquainted with Parallax Scrolling in Web Design. If you are using any modern day website on computers or mobile phones, you might have come across an effect when you scroll up/down the website, it appears like the whole screen is moving in the direction of scroll. If this is the effect in the background, the information in the foreground changes as you scroll. This effect can be vaguely described as Parallax Scrolling. As you read through this tutorial, you will understand the history of scrolling, how it evolved, the parallax scrolling definition and finally some plugins to help you get started with implementation of Parallax Scrolling. Print Page Previous Next Advertisements ”;

Concepts

Parallax Scrolling in Web Design – Concepts ”; Previous Next Now that we have understood the origin and background of Parallax, let us understand the history and the concept of Parallax scrolling in web design. Definition According to Wikipedia – Parallax scrolling is a technique in computer graphics where background images move past the camera more slowly than foreground images, creating an illusion of depth in a 2D scene and adding to the sense of immersion in the virtual experience. Parallax scrolling was employed in the early days of animation. Many of the animation studios (like Disney) used multiplane cameras to achieve the parallax effect. As the computer graphics technologies evolved along with the cutting edge frameworks like JavaScript, web designers and developers can now build sites with a rich experience. Although parallax scrolling started with a couple of layers, it was taken to the next level with scroll bars in computers. The technique remained the same, but due to its application for Scrolling, a unique experience was created. Examples The parallax scrolling is extensively used in modern web sites. As parallax scrolling can be implemented for mobiles as well as desktop sites in one go, the popularity of such sites has skyrocketed in the recent years. Some examples of websites that employ parallax scrolling are given below − Bear Grylls As the animation proceeds, you will be able to see how the website content is going interactive. As you scroll ahead, more and more information will reveal. Make Your Money Matter To introduce the reader to the benefits of a credit union, this site takes you through a storyline. As you scroll ahead, information is revealed in a unique way. InfoQuest Infographic The journey of an employee to find critical information at his workplace is depicted using the scrolling experience. GitHub 404 This is a bit different from the usual parallax experience, the object at the top of screen moves as you hover the mouse pointer over it. Applications of Parallax Scrolling By now, it should be clear from the definition and the background that parallax scrolling is useful in wide variety of digital media. Some of the applications are parallax scrolling are below − Game Design Parallax scrolling is widely used in game design. The character needs to move relative to the background and with the player’s control using mouse and keyboard, the whole experience needs to change. Game design is very primitive yet trendy way of using parallax scrolling. Websites To make the user gripped to the website, some dynamic and different experience is important. As you might have noticed from the examples of websites discussed above, parallax scrolling adds to the content because of its representation in an interactive manner. Print Page Previous Next Advertisements ”;

Conclusion

Parallax Scrolling in Web Design – Conclusion ”; Previous Next In this tutorial, we have studied different libraries for creating parallax scrolling. We have covered all aspects from basic level where we used CSS to advanced level wherewe used Bootstrap for front end development. We suggest you to apply your creative skills to come up with a web page which is hard to ignore. Remember that for parallax scrolling, there are enormous examples online to provide you an inspiration. Utilization of Parallax Scrolling As we have already discussed in the introductory chapters, you can use parallax scrolling to achieve an extraordinary user experience. Here are some ideas for website, where you can include parallax scrolling. Timeline Website These type of website usually have a story to tell about a product or company or anything else. You can create a parallax effect to put forth the story to the visitor and keep them engaged with different animations. For a timeline website, it will be worthwhile to create a background and show the text content in the foreground. You can team up with a graphic designer to create graphics which go hand in hand with the background. Mobile App Website Nowadays, mobile app is a must have for any product/service offering. There are many startups looking for creating mobile app website which provide an explanation of what the mobile app can and cannot do. Apple App Store, known for their strict app creation guidelines, demands the mobile app to have a support website. This website will always need to be attractive and user friendly. Using Parallax Scrolling, you can use a mobile image and show different types of functionalities as the user scrolls down the page. One such example is already discussed in Chapter 4 of this tutorial. Mouse Over Effect You can use the power of parallax scrolling and mouse over to create next level of animation. With mouse over, you can control the direction of scrolling and create a parallax effect. In this way, there are many possibilities when it comes to creating a great experience. All you need is an idea and right set of tools and libraries. Future of Web UI With the power of technology and creative elements like parallax scrolling, there is a never-before competition to create amazing user experiences. This is not just limited to websites but it has also got extended to mobile sites as well. While Web UI is currently at its peak, having a web page compatible with a mobile device is the need of time. As we have seen in the examples for Bootstrap and jQuery, the websites cannot live a long life if they are not supported on handheld devices. Along with the existing libraries, future of user experience eagerly looks forward to Artificial Intelligence and Virtual Reality as well. There are some webpages which are viewable using a VR gear. In such a situation, keeping in touch with the latest plugins and also looking for creating new one really makes sense. Apply the knowledge you gained in this tutorial for creating best of the user experience, wish you much luck and success to your web development journey! Print Page Previous Next Advertisements ”;

Quick Guide

Background and Introduction ”; Previous Next If you are browsing any modern day website on computers or mobile phones, you might have experienced that when you scroll down/up the website, it appears like the whole screen is moving in the direction of scroll. If this is the effect in the background, the information in the foreground too changes as you scroll. This effect can be briefly described as Parallax Scrolling. Scrolling Let us understand what it means by scrolling. When you are viewing a web page, the action for browsing the web page in any direction (up, down, left and right), is known as Scrolling. Usually, if you are a desktop computer user, this action is done by using the scroll wheel on the mouse. History Let us look at the word – Scroll. In olden days, to send a message to other people who are located at a great distance, handwritten scrolls were used. These scrolls looked like as shown below − Imagine the action of the person who is holding the scroll. To read the content in full, the person would have to “scroll” and roll it further. The use of these scrolls was also for maintaining a record text or decisions. As the time went by, the use of scroll increased as it was prepared from different writing materials such as – papyrus, parchment and paper. As the computers evolved, processing and storing very large documents, tables and images became possible. Sometimes the data was so much so that the screen size was just not sufficient to present the data to the user. When the data to be displayed was larger than the size of window or display area, the data would remain hidden. This necessitated for an approach of expanding the screen area. Some options to achieve expansion of screen are listed below − To increase the screen size To reduce the data size To use scrolling This scrolling mechanism is more important for people working with graphics design and photo editing. Parallax Scrolling Origin Let us look into the history of parallax scrolling. First, we will understand what the word parallax means. The word parallax comes from Greek word παράλλαξις (parallaxis), which means alternation. If we are viewing an object from an angle, the object will appear in a specific manner. But if you’re moving the same object from different positions, there will be an apparent movement of objects. This phenomenon is referred to as Parallax. Parallax Scrolling in Web Design – Concepts Now that we have understood the origin and background of Parallax, let us understand the history and the concept of Parallax scrolling in web design. Definition According to Wikipedia – Parallax scrolling is a technique in computer graphics where background images move past the camera more slowly than foreground images, creating an illusion of depth in a 2D scene and adding to the sense of immersion in the virtual experience. Parallax scrolling was employed in the early days of animation. Many of the animation studios (like Disney) used multiplane cameras to achieve the parallax effect. As the computer graphics technologies evolved along with the cutting edge frameworks like JavaScript, web designers and developers can now build sites with a rich experience. Although parallax scrolling started with a couple of layers, it was taken to the next level with scroll bars in computers. The technique remained the same, but due to its application for Scrolling, a unique experience was created. Examples The parallax scrolling is extensively used in modern web sites. As parallax scrolling can be implemented for mobiles as well as desktop sites in one go, the popularity of such sites has skyrocketed in the recent years. Some examples of websites that employ parallax scrolling are given below − Bear Grylls As the animation proceeds, you will be able to see how the website content is going interactive. As you scroll ahead, more and more information will reveal. Make Your Money Matter To introduce the reader to the benefits of a credit union, this site takes you through a storyline. As you scroll ahead, information is revealed in a unique way. InfoQuest Infographic The journey of an employee to find critical information at his workplace is depicted using the scrolling experience. GitHub 404 This is a bit different from the usual parallax experience, the object at the top of screen moves as you hover the mouse pointer over it. Applications of Parallax Scrolling By now, it should be clear from the definition and the background that parallax scrolling is useful in wide variety of digital media. Some of the applications are parallax scrolling are below − Game Design Parallax scrolling is widely used in game design. The character needs to move relative to the background and with the player’s control using mouse and keyboard, the whole experience needs to change. Game design is very primitive yet trendy way of using parallax scrolling. Websites To make the user gripped to the website, some dynamic and different experience is important. As you might have noticed from the examples of websites discussed above, parallax scrolling adds to the content because of its representation in an interactive manner. Web Design and Parallax Scroll This chapter talks about concepts of web design and advantages of using parallax scroll in web design. Web Design Background Since the beginning of 20th century, paper media has got into a cut-throat competition due to digital media. The digital media includes what we see on internet and hence the allied magazines that come along. The newsletters that you get as a part of weekly/monthly subscriptions are also included in the digital media. Primarily, digital media heavily depends on mobile and desktop devices. It makes a difference when you can see content on your mobile (handheld) as well as desktop devices. The way content is displayed on either of devices, a specific style of designing the content is at play. This style of designing is referred as Web Designing.

Useful Resources

Parallax Scrolling in Web Design – Resources ”; Previous Next The following resources contain additional information on Parallax Scrolling in Web Design. Please use them to get more in-depth knowledge on this. Useful Video Courses How To Start A Profitable Web Design Business 23 Lectures 2.5 hours Juan Galvan More Detail Web Design for Beginners: Build Websites in HTML & CSS 2022 68 Lectures 8 hours Web Coding More Detail Guide To Web Design Using Elementor & WordPress 32 Lectures 2.5 hours Being Commerce More Detail Create Professional Web Design without any HTML or CSS 32 Lectures 2.5 hours Being Commerce More Detail Build A Website Design For Any Business 62 Lectures 3.5 hours Music Course Online More Detail Adobe XD for Web Design: Essential Principles for UI and UX 108 Lectures 9.5 hours Packt Publishing More Detail Print Page Previous Next Advertisements ”;

JavaScript Techniques

JavaScript Techniques ”; Previous Next To create Parallax effect, the most popular method is using JavaScript. From this chapter onwards we will discuss the concepts of JavaScript and some of the libraries used to achieve Parallax scrolling. Utilizing pure JavaScript makes sense to keep the website performance optimal. There are many other advantages of using libraries from an aspect of performance. However, to understand the code organization better, we will start with pure JavaScript parallax implementation. Fun fact, sometimes pure JavaScript is also called vanilla JavaScript. Parallax Scrolling using Pure JavaScript First, create main HTML file with code shown below. The HTML page will just consist of four heading text. <html> <head> <link rel = “stylesheet” href = “styles.css”> <script src = “myscripts.js”></script> </head> <body> <section class = “parallax”> <h1>The First Scroll</h1> </section> <section class = “parallax”> <h1>The Second One</h1> </section> <section class = “parallax”> <h1>GoingOn !!</h1> </section> <section class = “parallax”> <h1>And we”ve reached the bottom!!</h1> </section> </body> </html> Observe that in line number 4, for this example, we are using myscripts.js file which will be stored in the same folder as the HTML file and CSS file. Now, let us prepare our CSS file as shown below. header { height: 4em; background: #845; } .parallax { background-repeat: no-repeat; background-size: cover; } .parallax h1 { text-align: center; margin: 0; font-size: 2.5em; letter-spacing: .2em; color: red; padding: 10rem 0; mix-blend-mode: exclusion; } .parallax:nth-of-type(1) { background: url(https://pixabay.com/get/ea35b10621f0083ed1534705fb0938c9bd22ffd41cb2114296f0c679a4/background-3009949_1920.jpg); } .parallax:nth-of-type(1) h1 { padding: 15rem 0; } .parallax:nth-of-type(2) { background: url(https://pixabay.com/get/ea35b10621f0083ed1534705fb0938c9bd22ffd41cb2114296f0c679a4/background-3009949_1920.jpg); } .parallax:nth-of-type(2) h1 { padding: 12rem 0; } .parallax:nth-of-type(3) { background: url(https://pixabay.com/get/ea35b10621f0083ed1534705fb0938c9bd22ffd41cb2114296f0c679a4/background-3009949_1920.jpg); } .parallax:nth-of-type(4) { background: url(https://pixabay.com/get/ea35b10621f0083ed1534705fb0938c9bd22ffd41cb2114296f0c679a4/background-3009949_1920.jpg); } Now comes the JavaScript part, create a file in notepad and save it as myscripts.js. function $$(selector, context) { context = context || document; var elements = context.querySelectorAll(selector); return Array.prototype.slice.call(elements); } window.addEventListener(“scroll”, function() { var scrolledHeight= window.pageYOffset; $$(“.parallax”).forEach(function(el,index,array) { var limit = el.offsetTop+ el.offsetHeight; if(scrolledHeight > el.offsetTop && scrolledHeight &l;= limit) { el.style.backgroundPositionY= (scrolledHeight – el.offsetTop) /1.5+ “px”; } else { el.style.backgroundPositionY= “0”; } }); }); Analysis of Code Let us analyze the JavaScript code. Code from line number 1 to 4 represents the helper function. In line 6, we select our parallax element and add scroll event to the window. To determine how much area is scrolled, we are using scrolledHeight property. As the screen scrolls down, backgroundPositionY is updated for the parallax element. To slow down the parallax effect, we divided by 1.5, this number can be changed to any number you want. Now, you will be able to see the page scrolling down as provided in below screenshot. Using ScrollMagic JavaScript Library As discussed in the previous section, while we can use pure JavaScript to create parallax effect, there are some powerful JavaScript libraries which will enhance the user experience. ScrollMagic is one such library for creating parallax scroll interactions. Let us discuss more about this with the help of an example as given below − Note − In this example, to keep it simple, we will have the CSS stored in HTML file. Also, the JavaScript code will be present in the same document. In a nutshell, we will create only one HTML file and it will have ScrollMagic libraries referenced along with the required CSS. <html> <head> <script src = “https://cdnjs.cloudflare.com/ajax/libs/gsap/2.0.1/TweenMax.min.js”></script> <script src = “http://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.5/ScrollMagic.js”></script> <script src = “http://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.5/plugins/animation.gsap.js”></script> <script src = “http://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.5/plugins/debug.addIndicators.js”></script> </head> <body> <style type = “text/css”> .parallaxParent { height: 100vh; overflow: hidden; } .parallaxParent > * { height: 200%; position: relative; top: -100%; } </style> <div class = “spacing0”></div> <div id = “parallax1” class = “parallaxParent”> <div style = “background-image: url(https://cdn.pixabay.com/photo/2015/05/16/19/13/stones-770264_640.jpg);”></div> </div> <div class = “spacing1”> <div style = “background-color:cyan”> <p>These are bricks</p> </div> </div> <div class = “spacing0″></div> <div id=”parallax2” class = “parallaxParent”> <div style = “background-image: url(https://cdn.pixabay.com/photo/2015/05/16/19/13/stones-770264_640.jpg);”></div> </div> <div class = “spacing1”> <div style = “background-color:yellow”> <p>Some More Bricks</p> </div> </div> <div class = “spacing0”></div> <div id = “parallax3” class = “parallaxParent”> <div style = “background-image: url(https://cdn.pixabay.com/photo/2015/05/16/19/13/stones-770264_640.jpg);”></div> </div> <div class = “spacing2”></div> <script> // init controller var controller = new ScrollMagic.Controller({ globalSceneOptions: {triggerHook: “onEnter”, duration: “200%”}}); // build scenes new ScrollMagic.Scene({triggerElement: “#parallax1”}) .setTween(“#parallax1 > div”, {y: “80%”, ease: Linear.easeNone}) .addIndicators() .addTo(controller); new ScrollMagic.Scene({triggerElement: “#parallax2”}) .setTween(“#parallax2 > div”, {y: “80%”, ease: Linear.easeNone}) .addIndicators() .addTo(controller); new ScrollMagic.Scene({triggerElement: “#parallax3”}) .setTween(“#parallax3 > div”, {y: “80%”, ease: Linear.easeNone}) .addIndicators() .addTo(controller); </script> </body> </html> As shown in the above code, we have required JavaScript libraries references from line 3 to 6. The CSS code is specified from line 9 to 19. Content Delivery Network Script references from line 3 to 6 point to ScrollMagic Content Delivery Network (CDN) URLs. Using a CDN makes sense in modern website development, as you get to load the required libraries without slowing down your website. If there are customizations required in the libraries, one would have to host the libraries on their respective server to utilize these effects. If you are using basic functionalities from a library, it is efficient to use the CDN URL. The HTML code above shows an image separated by 2 divisions. First division appears with a heading – These are bricks and second division appears with – Some More Bricks. Notice that in the CSS code from line 9 to 19, we are only specifying the position and style for the respective parallax div. The work of creating this soft parallax scene is done by ScrollMagic library. If you refer to script code from line 43 to 62, ScrollMagic controller is invoked and a scene is created. The scenes guide the DOM to create parallax effect when 80% of the screen is occupied. JavaScript is used to understand the scroll trigger. As a result, what you get is a floating experience on this page. Note − Considering above image as a GIF image, you will not get to observe the smooth effect of the text divisions. Trigger Animations The possibilities of creating varied user experience are endless with ScrollMagic Library. Observe the code snippets given below to trigger animations on scroll. Note that for this

Background and Introduction

Background and Introduction ”; Previous Next If you are browsing any modern day website on computers or mobile phones, you might have experienced that when you scroll down/up the website, it appears like the whole screen is moving in the direction of scroll. If this is the effect in the background, the information in the foreground too changes as you scroll. This effect can be briefly described as Parallax Scrolling. Scrolling Let us understand what it means by scrolling. When you are viewing a web page, the action for browsing the web page in any direction (up, down, left and right), is known as Scrolling. Usually, if you are a desktop computer user, this action is done by using the scroll wheel on the mouse. History Let us look at the word – Scroll. In olden days, to send a message to other people who are located at a great distance, handwritten scrolls were used. These scrolls looked like as shown below − Imagine the action of the person who is holding the scroll. To read the content in full, the person would have to “scroll” and roll it further. The use of these scrolls was also for maintaining a record text or decisions. As the time went by, the use of scroll increased as it was prepared from different writing materials such as – papyrus, parchment and paper. As the computers evolved, processing and storing very large documents, tables and images became possible. Sometimes the data was so much so that the screen size was just not sufficient to present the data to the user. When the data to be displayed was larger than the size of window or display area, the data would remain hidden. This necessitated for an approach of expanding the screen area. Some options to achieve expansion of screen are listed below − To increase the screen size To reduce the data size To use scrolling This scrolling mechanism is more important for people working with graphics design and photo editing. Parallax Scrolling Origin Let us look into the history of parallax scrolling. First, we will understand what the word parallax means. The word parallax comes from Greek word παράλλαξις (parallaxis), which means alternation. If we are viewing an object from an angle, the object will appear in a specific manner. But if you’re moving the same object from different positions, there will be an apparent movement of objects. This phenomenon is referred to as Parallax. Print Page Previous Next Advertisements ”;

Home

Parallax Scrolling in Web Design Tutorial PDF Version Quick Guide Resources Job Search Discussion This tutorial aims to make you acquainted with Parallax Scrolling in Web Design. If you are using any modern day website on computers or mobile phones, you might have come across an effect when you scroll up/down the website, it appears like the whole screen is moving in the direction of scroll. If this is the effect in the background, the information in the foreground changes as you scroll. This effect can be vaguely described as Parallax Scrolling. As you read through this tutorial, you will understand the history of scrolling, how it evolved, the parallax scrolling definition and finally some plugins to help you get started with implementation of Parallax Scrolling. Audience Any aspiring web designer who wants to gain a deeper understanding of parallax scrolling effect in web designing can read this tutorial. If you have an eye for detail when designing and using websites on desktops, laptops and other handheld electronic devices, you will gain a solid understanding of parallax scrolling concept in web design through this tutorial. Prerequisites This tutorial is written keeping in mind that the learners have an idea of basic knowledge of web design. An introductory knowledge of HTML, CSS and jQuery would be an added advantage for the learner. If you are a beginner to any of these concepts, we suggest you to go through tutorials related to these before you start with this tutorial. Print Page Previous Next Advertisements ”;