cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class ='bg'> </div>
<div class = 'container'>
<div class ='favourite'>

  </div>
  <form class ='form'>
  <input type = 'search' placeholder ='search a film'>
  <button type ='submit'> Search </button>
    <i class="fa fa-star view-fav" aria-hidden="true"></i>

  </form>
    <div class ='error'> </div>
</div>
<div class = 'selectedFilm'> </div>
<div class ='container'>
  
  <ul class ='films'>

  </ul>
</div>
<div id ='result'> </div>
            
          
!
            
              $black: rgba(0, 0, 0, 0.8);
* { 
  box-sizing: border-box;
  list-style:none;
  max-width:100%;

}
ul {
  padding:0;
}
body {
    font-family: 'Poppins', sans-serif;
}
form {
  background:$black;
  padding:5px;
}
input[type=search] { 
	color: black;  
	text-align: left;
	cursor: pointer;
	display: inline-block; 
	letter-spacing: 4px;             
	word-spacing: 20px; 
 
}
.container {
  width:800px;
  margin:0 auto;
  position:relative;
}

.films {
  display:grid;
  grid-template-columns: 23% 23% 23% 23%;
  grid-gap: 2.6%;
  cursor:pointer;

  
  .title {
    font-size: 18px;
    
  }
}
.selectedFilm__poster {
  width:200px;
}
.selectedFilm__img {
  width:40%;
}
.selectedFilm__content{
  width:59%;
}
.selectedFilm div {
  display:inline-block;
  vertical-align:top;
  padding:20px;
}
.selectedFilm {
    width: 750px;
    margin: 0 auto;
    position: fixed;
    background: white;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  z-index:2;
  border-radius:5px;
  p {
    font-size:13px;
  }
}
.selectedFilm__backdrop {
  position: absolute;
    left: 50%;
    top: 65%;
    transform: translate(-50%, -50%);
  display:none;
}
.bg {
    display:none;
    background: $black;
    z-index: 1;
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
}
.fa-times {
  position:absolute;
  right:10px;
  top:10px;
  font-size:20px;
  cursor:pointer;
}
.favImg {
width:100%;
}
.view-fav {
    color: gold;
    right: 5px;
    padding: 5px;
    z-index: 5;
    position: absolute;
}
.favourite {
    position: absolute;
    background: $black;
    width: 20%;

    right:0;
    top:35px;
    z-index:2;
    display:none;
  
  img {
        padding: 10px;
  }
}
.add-fav {
  display:inline-block;
  background:$black;
  color:#fff;
  letter-spacing:px;
  padding:5px 10px;
  cursor:pointer;
  font-size:14px;
 
  &:hover .fa {
    color:gold;
  }
  .fa {
    margin-left:5px;
    transition: .3s all;
  }
}
.favourite__close {
  color:#fff;
}

            
          
!
            
              function loadData(event) {
  event.preventDefault();
  // only display favourite list if items are there
$(".view-fav").on("click", function() {
  if ($.trim($(".favourite").html()).length) {
    $(".favourite").fadeToggle();
    $(".bg").fadeToggle();
  }
});

  let search;
  // check if no input
  // set default search to jaws
  if (!$("input").val()) {
    search = "bond";
  } else {
    search = $("input").val();
    $("input").val("");
  }

  // api and end points
  // create search with user input
  const api = "&api_key=feb6f0eeaa0a72662967d77079850353";
  const endpoint = `https://api.themoviedb.org/3/search/movie?query=${search}${api}`;
  const poster = "https://image.tmdb.org/t/p/w600/";

  let gridHtml = "";
  let selectedHtml = "";

  $.getJSON(endpoint, function(data) {

    // show film details in pop up
    $("body").on("click", "li", function(e) {
      $(".view-fav").fadeToggle();
      $(".selectedFilm").fadeIn();
      $(".bg").fadeToggle();
      // get number of list item
      // match this the data returned in results
      // to be able to pull through same info
      let index = $("li").index(this);
      let selected = data.results[index];
      // creating film pop up layout and info
      gridHtml = `
 <i class="fa fa-times close" aria-hidden="true"></i>
        <div class="selectedFilm__img">
                <img class ="selectedFilm__poster" src ="${poster}${selected.poster_path}">
         </div>
         <div class="selectedFilm__content">
            <h2>${selected.title}</h2>
            <h3>Overview</h3>
            <p>${selected.overview}</p>
        
        <span class ='add-fav'>Add to favourites <i class="fa fa-star" aria-hidden="true"></i></span>
        </div>`;
      $(".selectedFilm").html(gridHtml);

      // close the pop up
      $(".close").on("click", function() {
        $(".selectedFilm").fadeOut();
        $(".bg").fadeToggle();
        $(".view-fav").fadeToggle();
      });
    });
    // if no results display error message
    if (data.results.length == 0) {
      $(".error").html("No data found, search again.");
    }
    // create the film layout
    for (let i = 0; i < data.results.length; i++) {
      const movieResults = data.results[i];
      gridHtml += `<li>
        <img src = "${poster}${movieResults.poster_path}">
    </li>`;
    }

    $(".films").html(gridHtml);
  });

  // click of pop up image - add to favourites div
  $("body").on("click", ".add-fav", function() {
    // get the img src
    let favItems = $(".selectedFilm__poster").attr("src");
    $(".favourite").append(`<img class ="favImg" src ="${favItems}">`);
    // bug - unsure why? duplicate images being displayed on click.
    // removed any duplicated src
    var img = $(".favImg");
    var used = {};

    img.each(function() {
      var src = $(this).attr("src");
      if (used[src]) $(this).remove();
      used[src] = 1;
    });
    localStorage.getItem(favItems);
  });
  localStorage.setItem(favItems);
 
}
// start app


// use submit to load the data
const form = $(".form");
form.submit(loadData);

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console