• Stars
    star
    311
  • Rank 134,521 (Top 3 %)
  • Language
    JavaScript
  • Created almost 8 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Full Screen Background Slider for Yelp Camp

Full Screen Background Image Slider

This tutorial uses HTML and CSS to create a full screen background image slider that uses a crossfade effect to transition between images. The images will be set as background-images to a modified unordered list. We'll use 5 images with 10 second intervals for a 50 second animation cycle.

Markup

  • Edit the landing.ejs page to look like the following:
<!DOCTYPE html>
<html>
    <head>
        <title>YelpCamp</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
        <link rel="stylesheet" href="/stylesheets/landing.css">
        <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js" type="text/javascript" async></script>
    </head>
    <body>
    
    <div class="container">
        <% if(error && error.length > 0){ %>
            <div class="alert alert-danger" role="alert">
                <%= error %>
            </div>
        <% } %>
        <% if(success && success.length > 0){ %>
            <div class="alert alert-success" role="alert">
                <%= success %>
            </div>
        <% } %>
    </div>
    
    <div id="landing-header">
 		<h1>Welcome to YelpCamp!</h1>
		<a href="/campgrounds" class="btn btn-lg btn-success">View All Campgrounds</a>
    </div>
    
    <ul class="slideshow">
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
    </ul>

<% include partials/footer %>

CSS

  • Create a new CSS file in /public/stylesheets named landing.css
  • Open landing.css and set the body's background-color to black
body {
  background-color: #000;
}
  • Now we need to position the welcome text and view all campgrounds buton:
#landing-header {
  z-index: 1;
  position: relative;
  text-align: center;
  padding-top: 40vh;
}
  • We set the z-index to 1 so all of the elements inside the landing-header div will be in front of the background images

  • The position is set to relative so we can use the z-index property; the default position value is static, which ignores z-index

  • We use text-align to center our text and button

  • We use padding-top to vertically center our div, since it's contents take up quite a bit of space we use 40vh (view height) instead of 50, this way the content looks more visually centered

  • We also need to change the h1 text color to white:

#landing-header h1 {
  color: #fff;
}
  • The unordered list and its list items that we added to landing.ejs need some styling to make them fit across the entire page
  • First we'll style the unordered list:
.slideshow { 
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  z-index: 0;
  list-style: none;
  margin: 0;
  padding: 0;
}
  • This will fix the ul to the window, positioning it in the top left corner and filling the entire screen by setting width and height to 100%; we set the z-index to 0 to keep the background images behind the rest of the page's content; list-style is set to none in order to hide the bullet points from the list's default styling; margin and padding are removed entirely

  • Now we can style all of the list items:

.slideshow li { 
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  background-size: cover;
  background-position: 50% 50%;
  background-repeat: no-repeat;
  opacity: 0;
  z-index: 0;
  animation: imageAnimation 50s linear infinite; 
}
  • Notice the animation property at the bottom of this rule, this is how we add an animation to an element; in this case we have an animation named imageAnimation that lasts for 50s (seconds), keeps linear timing (the whole animation runs at the same speed), and loops an infinite number of times

  • Each list item needs a background-image and the last four need an animation-delay (this way they all fire off one after the other in ten second intervals):

.slideshow li:nth-child(1) { 
  background-image: url(http://i.imgur.com/K3mPv14.jpg) 
}
.slideshow li:nth-child(2) { 
  background-image: url(http://i.imgur.com/SBEmFpv.jpg);
  animation-delay: 10s; 
}
.slideshow li:nth-child(3) { 
  background-image: url(http://i.imgur.com/emvhOnb.jpg);
  animation-delay: 20s; 
}
.slideshow li:nth-child(4) { 
  background-image: url(http://i.imgur.com/2LSMCmJ.jpg);
  animation-delay: 30s; 
}
.slideshow li:nth-child(5) { 
  background-image: url(http://i.imgur.com/TVGe0Ef.jpg);
  animation-delay: 40s; 
}
  • Now we can create the keyframes for the animation:
@keyframes imageAnimation { 
  0% { 
    opacity: 0; 
    animation-timing-function: ease-in;
  }
  10% {
    opacity: 1;
    animation-timing-function: ease-out;
  }
  20% {
    opacity: 1
  }
  30% {
    opacity: 0
  }
}
  • The animation will be named imageAnimation, which matches with the value from our animation property in the .slideshow (unordered list) rule

    • From 0% to 10% (the beginning of our animation) the list item begins changing it's opacity from 0 to 1 (invisible to visible)
    • the animation-timing-function is set to ease-in at 0% and ease-out and 10%, this makes for a more smooth fade-in (read more about this here)
    • The list item's opacity then stays at 1 until it reaches 20% at which point it fades back out, reaching 0 at 30% and staying at 0 for the remainder of the animation
    • If we have 5 background images visible for 5 seconds each, then the time it takes to fade the image in and keep it visible is 10 seconds with a 5 second crossfade/fadeout into the next image; The entire animation cycle for all 5 images takes 50 seconds total
    • 100% divided by 5 is 20% so each image's fadein and visibility should last 20% of the cycle; half of 20% is 10%, that is why our fade in is from 0% to 10%, then we keep it visible until 20% is reached and begin the fadeout from 20% to 30%, the 5 second fadeout overlaps the next image's 5 second fadein, which is what creates the crossfade effect
  • Lastly, we need to add animation support for older browsers; we've already added the modernizr CDN to our landing page's head element, now we just need the following rule in our landing.css:

/* Older browser support - .no-cssanimations class added by modernizr */
.no-cssanimations .slideshow li {
	opacity: 1;
}

And that's it!

You now have a full screen background slider. If you're interested in learning more about animations with CSS checkout this tutorial

More Repositories

1

webdevbootcamp

All source code for back-end projects from the Web Developer Bootcamp
HTML
1,800
star
2

yelp-camp-refactored

Refactor of YelpCamp project with Express JS
JavaScript
320
star
3

node-and-mysql

Colt Steele's Node and MyQL workspace from The Ultimate MySQL Bootcamp on Udemy.com
JavaScript
99
star
4

aws-cloud9-instructions

Instructions for setting up an AWS account and using Cloud9
63
star
5

image_upload_example

Image upload with Node, Express, Multer, and Cloudinary
JavaScript
57
star
6

angular-express-passport-tutorial

A quick source code tutorial for adding passport authentication to a MEAN stack app (Facebook integration included)
JavaScript
52
star
7

ajax-jquery-tutorial

Learn AJAX with jQuery
HTML
41
star
8

dynamic-price

YelCamp - dynamic price feature - Web Developer Bootcamp
JavaScript
31
star
9

learn-web-dev

General roadmap/guide to help anyone who wants to learn to code
28
star
10

fuzzy-search

Source code for fuzzy search tutorial
JavaScript
26
star
11

surf-shop

The official Surf Shop application from DevSprout.io's Code w/ Node course.
JavaScript
20
star
12

google-maps-api

Google Maps API - YelpCamp Tutorial
JavaScript
16
star
13

codeanywhere-instructions

Instructions for setting up Node and Mongodb with Codeanywhere Cloud IDE
15
star
14

yelpcamp-user-notifications

Follow other users and get notified when they create new campgrounds
JavaScript
14
star
15

yelpcamp-contact-form

Send emails from an Express JS contact form using the Twilio SendGrid API
JavaScript
11
star
16

yelpcamp-stripe-payment

YelpCamp Project with One-time Payment (via Stripe) after User Signup
JavaScript
11
star
17

yelp-camp-rating-system

Rating system for YelpCamp - The Web Developer Bootcamp
JavaScript
10
star
18

craigslist-clone

Build a clone of craigslist using Ruby on Rails
Ruby
9
star
19

facebook-auth-express

Learn how to set up Facebook authentication with Passport and Express JS
JavaScript
9
star
20

res-locals-demo

Learn how to pass data through middleware in Express JS
JavaScript
8
star
21

jquery-ajax-spa

SPA application for jQuery AJAX course
JavaScript
5
star
22

mysql-instructions

Instructions for setting up MySQL with Codeanywhere IDE
5
star
23

stripe-checkout

Learn how to easily integrate Stripe's payment portal with the popular Express JS framework in this half hour tutorial.
JavaScript
5
star
24

wdb-faq

A work in progress FAQ application for The Web Developer Bootcamp on Udemy
JavaScript
5
star
25

craigs-boards

Source code for preview site from Code w/ Node (similar to Surf Shop project)
JavaScript
5
star
26

YelpCamp-Error-Handling-Bug-Fix

Fix for YelpCamp error handing bug
JavaScript
4
star
27

yelp-camp-es6

Refactor of YelpCamp using some ES6 syntax
JavaScript
4
star
28

learn-and-earn-leaderboard

Leader Board App for the Learn and Earn Contest at the Web Developer Bootcamp
JavaScript
4
star
29

html-css-basics

Learn the basics of HTML and CSS
HTML
4
star
30

callbacks-to-async-await

Turn Callbacks Into Async + Await
JavaScript
3
star
31

YelpCamp-Updates-2022

YelpCamp app with dependency updates through June 2022
JavaScript
3
star
32

yelpcamp-add-ons

Add-on features for Colt Steele's YelpCamp project from The Web Developer Bootcamp 2021
JavaScript
3
star
33

interview-handbook

interview questions for students
3
star
34

course-deals

JavaScript
3
star
35

v11Deployed

JavaScript
3
star
36

static-images-express-js

Learn how to connect static image assets to an Express JS application
JavaScript
2
star
37

node-ecommerce-project

Testing out Stipe API with Node
JavaScript
2
star
38

local-variables-express

Learn about local variables in Express JS
JavaScript
2
star
39

new-edit-form-demo

Learn how to DRY up your Express JS forms with this quick and easy tutorial
JavaScript
2
star
40

GitGrub

General Assembly Web Development Immersive - Project 2
Ruby
1
star
41

simple-arcgis-geocoding-api-test

Simple Test of the Arcgis Geocoding API
JavaScript
1
star
42

satellizer-demo

code from https://github.com/sahat/satellizer
JavaScript
1
star
43

ecommerce-experiment

ecommerce-experiment
JavaScript
1
star
44

Attendance-app

A simple app for tracking student attendance with QR codes
Ruby
1
star
45

automated-payroll

JavaScript
1
star
46

htmx-fun

demo todos app using express js and htmx
EJS
1
star
47

udemy-automation

Automate link finding process on Udemy Q&A with Selenium-webdriver and NodeJS
JavaScript
1
star
48

express-blog

JavaScript
1
star
49

json_api_demo

iXperience JSON API Demo
Ruby
1
star
50

yelp-camp-v11

Yelp Camp Refactor
JavaScript
1
star
51

MEAN-Blog

MEAN Stack app in progress
JavaScript
1
star
52

Mobile-QR-Scanner

First part of a multipart project that will allow users to log themselves into class attendance from their mobile phone.
JavaScript
1
star
53

jumping-jack-algorithm

A node js solution for the jumping (hopping) jack algorithm
JavaScript
1
star
54

Health-Journal

Final project for BEWD
JavaScript
1
star
55

generator-functions

A short lecture on generator functions in javascript
1
star
56

angular-promises

A quick source code tutorial for using the $q library in AngularJS
JavaScript
1
star
57

Bookbook

General Assembly Web Development Immersive - Project 1
HTML
1
star
58

devsprout-udemy-affiliate-chrome-extension

DevSprout Chrome Extension for Adding Udemy Affiliate Query String to URL
JavaScript
1
star
59

angular-services

Lecture notes for angular services
JavaScript
1
star
60

image-optimization-automation

Instantly optimize your static website's images and increase pagespeeds with this Cloudinary python automation
1
star
61

owasp-password-strength-test

OWASP Password Strength Test For Node/Express JS
JavaScript
1
star
62

interview-questions

TTS - DAL - 2016 - FALL
Ruby
1
star
63

django-ec2-fun

Deploy Django on AWS EC2
Python
1
star
64

intro-to-git

introduction to git
1
star
65

pocketbase_express_htmx

EJS
1
star