css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <button>slideLeft1</button>
<button>slideLeft2</button>
<button>slideRight1</button>
<button>slideRight2</button>
<div class = "outer"> 
  <div class = "inner online">
  </div>
  <div class = "inner all">
  </div>
  <div class = "inner offline" id = "active">
  </div>
  </div>
</div>


            
          
!
            
              body, html {
  height : 100%;
}

h3 {
	font-size: 20.5px;
	margin : 1.5vh auto;
	line-height: 120%;
	display : inline-block;

}

h4 {
	font-size : 17.5px;
	margin : 1.5vh auto;
	line-height : 120%;

}

.featured-streamer{
	display: inline-block;
  text-align : center;
	width : 100%;
	margin : 3vh auto;
}

.outer {
  position : relative;
  width : 33%;
  margin : 0 auto;
  border : solid purple;
  overflow : hidden;
  transition : height 300ms ease-in-out;
}

.inner {
  position : absolute;
  width : 100%;
  transition : left 300ms ease-in-out;
}

.online {
  border : solid;
  background : red;
  left : -100%;
}

.all {
  background : green;
}

.offline {
  background : blue;
  left : 100%;
}

.img {
	width : 95%;
	height : 180px;
	margin : 0 auto;
}
            
          
!
            
              document.addEventListener("DOMContentLoaded", function() {
  getArrayStreams("brad", bradStreams);
  for (var i = 0; i < 3 ; i++){
    left = (i-1) * 100;
    left += "%";
    document.getElementsByClassName("inner")[i].style.left = left;
  }
  heights();
});

document.getElementsByTagName("button")[0].addEventListener("click", slide.bind(this, "left", 1));
document.getElementsByTagName("button")[1].addEventListener("click", slide.bind(this, "left", 2));
document.getElementsByTagName("button")[2].addEventListener("click", slide.bind(this, "right", 1));
document.getElementsByTagName("button")[3].addEventListener("click", slide.bind(this, "right", 2));

var json, left;
var bradStreams = ["foggedftw2", "boxerpete", "neace", "imaqtpie", "loltyler1", "tobiasfate", "karnrs"];

function getJSON(query) {
  var request = new XMLHttpRequest();
  request.open(
    "GET",
    "https://wind-bow.glitch.me/twitch-api/" + query,
    false
  );

  request.onload = function() {
    if (this.status >= 200 && this.status < 400) {
      console.log("success");
      json = JSON.parse(this.response);
    } else {
      for (var i = 0; i < document.getElementsByClassName("featured").length; i++) {
        document.getElementsByClassName("featured")[i].innerHTML += "We reached our target server, but it returned an error.";
      }
    }
  };

  request.onerror = function() {
    for (var i = 0; i < document.getElementsByClassName("featured").length; i++) {
        document.getElementsByClassName("featured")[i].innerHTML += "There was a connection error of some sort.";
      }
    }

  request.send();
}

function htmlGenerator (isItTwitch, isItSearch, i) {
  if (isItTwitch) {
    var generator = '<div class = "featured-streamer"><a target = "_blank" href = "https://www.twitch.tv/' + 
        json.featured[i].stream.channel.display_name + '"><h3>'
         + json.featured[i].stream.channel.status + 
         '</h3></a><h4>Currently playing : <a target = "_blank" href = "https://www.twitch.tv/directory/game/' + 
         encodeURIComponent(json.featured[i].stream.channel.game) + '">'
          + json.featured[i].stream.channel.game + '</h4></a><a target = "_blank" href = "https://www.twitch.tv/' 
          + json.featured[i].stream.channel.display_name + 
          '"><img src = "' + json.featured[i].stream.preview.medium + '" class = "img"></img></a><br><h4>' + json.featured[i].stream.viewers +
              ' viewers on <a target = "_blank" href = "https://www.twitch.tv/' + json.featured[i].stream.channel.display_name + '">' 
              + json.featured[i].stream.channel.display_name + '</a></h4></div>';


  } else if (isItSearch) {
      generator = 
        '<span class = "button-span"><button class = "close">&times;</button></span><div class = "featured-streamer height-set featured-streamer-search"><a target = "_blank" href = "https://www.twitch.tv/' + json.stream.channel.display_name + '"><h3>'
         + json.stream.channel.status + '</h3></a><h4>Currently playing : <a target = "_blank" href = "https://www.twitch.tv/directory/game/' + 
         encodeURIComponent(json.stream.channel.game) + '">'
          + json.stream.channel.game + '</h4></a><a target = "_blank" href = "https://www.twitch.tv/' + json.stream.channel.display_name + 
          '"><img src = "' + json.stream.preview.medium + '" class = "img"></img></a><h4>' + json.stream.viewers +
              ' viewers on <a target = "_blank" href = "https://www.twitch.tv/' + json.stream.channel.display_name + '">' 
              + json.stream.channel.display_name + '</a></h4></div>';
  } else {
    generator = 
        '<div class = "featured-streamer height-set"><a target = "_blank" href = "https://www.twitch.tv/' + json.stream.channel.display_name + '"><h3>'
         + json.stream.channel.status + '</h3></a><h4>Currently playing : <a target = "_blank" href = "https://www.twitch.tv/directory/game/' + 
         encodeURIComponent(json.stream.channel.game) + '">'
          + json.stream.channel.game + '</h4></a><a target = "_blank" href = "https://www.twitch.tv/' + json.stream.channel.display_name + 
          '"><img src = "' + json.stream.preview.medium + '" class = "img"></img></a><h4>' + json.stream.viewers +
              ' viewers on <a target = "_blank" href = "https://www.twitch.tv/' + json.stream.channel.display_name + '">' 
              + json.stream.channel.display_name + '</a></h4></div>';

  }
  return generator;
}


function getArrayStreams(recommendedBy, arr){
  var offlineArr = [];
  var generator;
  document.getElementsByClassName("online")[0].innerHTML = "";
  document.getElementsByClassName("all")[0].innerHTML = "";
  document.getElementsByClassName("offline")[0].innerHTML = "";
  for (var i = 0; i < arr.length; i++){
    getJSON("/streams/" + arr[i]);
    if (!json.stream === null){
      generator = htmlGenerator(false, false);
      document.getElementsByClassName("all")[0].innerHTML += generator;
      document.getElementsByClassName("online")[0].innerHTML += generator;
    } else {
      offlineArr.push(arr[i])
    }
  }
  for (var j = 0; j < offlineArr.length; j++){
    getJSON("channels/" + offlineArr[j]);
    document.getElementsByClassName("offline")[0].innerHTML += 
    '<div class = "offline-streamer height-set2"><h3 class = "status">' + offlineArr[j] + ' is offline!</h3><img class = "logo" src="' + json.logo + '"></div>';
  }
}

function heights() {
  var active = Number(removePercent(document.getElementsByClassName("inner")[0].style.left));
  var height1 = document.getElementsByClassName("online")[0].offsetHeight;
  var height2 = document.getElementsByClassName("all")[0].offsetHeight;
  var height3 = document.getElementsByClassName("offline")[0].offsetHeight;
  if (active === -200){
    document.getElementsByClassName("outer")[0].style.height = height3 + "px";
  } else if (active === -100){
    document.getElementsByClassName("outer")[0].style.height = height2 + "px";
  } else {
    document.getElementsByClassName("outer")[0].style.height = height1 + "px";
  }
  
}

function removePercent(toBeTrimmed) {
  var trimmed = toBeTrimmed.slice(0, toBeTrimmed.length -1);
  return trimmed;
}

function slide(direction, distance) {
  var result;
  var check = Number(removePercent(document.getElementsByClassName("inner")[0].style.left));
    for (var i = 0; i < 3; i++){
      result = Number(removePercent(document.getElementsByClassName("inner")[i].style.left));
      if (check > -200 && direction === "left" && distance === 1){
        result -= 100;    
      } else if (check > -100 && direction === "left" && distance === 2){
        result -= 200; 
        } else if (check < 0 && direction === "right" && distance === 1){
          result = result + 100;  
        } else if (check < -100 && direction === "right" && distance === 2){
          result += 200;
        }
      result = result + "%";
      document.getElementsByClassName("inner")[i].style.left = result;  
    } 
  heights();
}
            
          
!
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