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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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 lang="en">

<head>
    <title>codePen TwitchTV</title>
    <meta charset="utf-8" />
    <meta name="author" content="Stu Keenan">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
    <script type="application/javascript" src="twitchTV.js"></script>
    <link rel="stylesheet" type="text/css" href="twitchTV.css" />

</head>

<body>
    <div class="wrapper">
        <div class="container" id="twitchContainer">
            <header class="header">
                <h1>TwitchTV</h1>
            </header>
            <ul class="menu" id="dropdownWrapper">
                <li id="dropdown">
                    <div id="dropbtn">
                        <div id="hamWrap">
                            <div class="hamburger" id="hbTop"></div>
                            <div class="hamburger" id="hbMiddle"></div>
                            <div class="hamburger" id="hbBottom"></div>
                            <span id="circle"></span>
                        </div>
                    </div>
                    <ul class="dropdownContent">
                        <li class="searchBar">
                            <form>
                                <input type="search" id="searchField" name="search">
                                <input type="submit" value="search">
                            </form>
                        </li>
                        <li class="filterOpt">
                            <input type="radio" id="displayAll" name="display" value="all" checked>
                            <label for="displayAll">all</label>
                            <div class="radioContain" id="activeRadio">
                                <input type="radio" id="displayActive" name="display" value="active">
                            </div>
                            <label for="displayActive">active</label>
                            <div class="radioContain" id="offlineRadio">
                                <input type="radio" id="displayOffline" name="display" value="offline">
                            </div>
                            <label for="displayOffline">offline</label>
                        </li>
                        <li class="expandOpt">
                            <input type="checkbox" id="expandAll" name="display" value="expand">
                            <label for="expandAll">expand all</label>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
        <p>Stu K. 2018</p>
    </div>
</body>

</html>
            
          
!
            
              body {
    background-color: #5b2838;
    text-align: center;
}

.wrapper {
    display: grid;
    grid-template-areas: 
        "container";
}

.container {
    grid-area: container;
    display: grid;
    grid-template-areas: 
        "header"
        "dropdownMenu";
    grid-gap: 0.75em;
    width: 100%;
    margin: 2.5% auto 1%;
    justify-items: center;
    background-color: #9E1946;
    border-radius: 15px;
    padding: 1% 0 2.5%;
    overflow: hidden;
}

.header, #dropbtn, .dropdownContent li {
    border-radius: 15px;
    text-align: center;
    width: 100%;
    background-color: #f3d9b1;
    color: #9E1946;
    padding: 0.15em 0;
    margin: 0.25em 0;
}

#dropbtn {
    margin: 0;
}

#dropdown {
    grid-area: dropdownMenu;
    position: relative;
    display: block; 
}

.menu, .dropdownContent {
    list-style-type: none;
    width: inherit;
    padding: 0;
    margin: 0;
}

.dropdownContent {
    display: none;
    position: relative;
    font-weight: bold;
}

h1 {
    margin: 0.15em 0;
}

.header {
    grid-area: header;
}

input[type=submit] {
    border-radius: 15px;
    border: 1px solid #9E1946;
    padding: .25% 2%;
    color: #9E1946;
    background-color: #f1f1f1;
    font-weight: inherit;
}

.radioContain {
    display: inline-block;
    border-radius: 100px;
}
  
.radioContain input[type="radio"] {
    display: block;
    margin: 0;
}

#activeRadio {
    box-shadow: 0 0 5px 3px #f15025;
}

#offlineRadio {
    box-shadow: 0 0 5px 3px #1f1d1d;
}

/**--HAMBURGER MENU START--*/
#hamWrap {
    position: relative;
    display: inline-block;
    height: 25px;
    width: 37.5px;
    padding-top: .1%;
}

.hamburger {
    width: inherit;
    height: 20%;
    background-color: #9E1946;
    margin: 7% auto 0;
    border-radius: 15px;
    transition: all 0.5s;
}

#circle {
    position: absolute;
    display: inline-block;
    height: .1rem;
    width: .1rem;
    opacity: 0;
    border: .2rem solid #9E1946;
    border-radius: 100%;
    left: 49.5%;
    top: 55%;
    transition: all 0.3s;
    transform: translate(-50%, -50%)
}

#hamWrap:hover #hbMiddle {
   transform: scale(0.75, 7.5);
   border-radius: 100%;
   opacity: 0;
}

#hamWrap:hover #hbTop {
    transform: translate(-45%, 124%) rotateZ(-90deg);
    opacity: 0;
}

#hamWrap:hover #hbBottom {
    transform: translate(45%, -124%) rotateZ(90deg);
    opacity: 0;
}

#hamWrap:hover #circle {
    opacity: 1.0;
    width: 1.25rem;
    height: 1.25rem;
}

.hbTopX {
    transform: translate(0, 150%) rotateZ(-45deg);
}

.hbBottomX {
    transform: translate(0, -150%) rotateZ(45deg);
}

.hbMiddleX {
    opacity: 0;
}
/**--HAMBURGER MENU END--*/

.twitchLine {
    display: grid;
    grid-template-areas: 
    "logo name"
    "logo desc";
    grid-template-columns: 75px 1fr;
    grid-column-gap: 5px;
    border-radius: 50px;
    height: 75px;
    width: 75px;
    transition: width 1s;
    background-color: #f3d9b1;
    align-items: center;
    text-align: center;
    color: black;
}

.wide {
    width: 100%;
}

.active {
    box-shadow: 0 0 5px 3px #f15025;
}

.offline {
    box-shadow: 0 0 5px 3px #1f1d1d;
}

.twitchLine:hover {
    width: 100%;
}

img {
    border-radius: 100%;
}

.logo {
    grid-area: logo;
    justify-self: start;
    z-index: 3;
}

.streamName {
    grid-area: name;
    z-index: 1;
    overflow: hidden;
    white-space: nowrap;
}

.streamDesc {
    grid-area: desc;
    z-index: 2;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

@media screen and (min-width: 768px) {
    .container {
        width: 75%;
    }

    .header, .menu {
        width: 85%;
    }
    
    .wide {
        width: 50%;
    }

    .twitchLine:hover {
        width: 50%
    }

}
            
          
!
            
              const streams = ['ESL_SC2', 'OgamingSC2', 'cretetion', 'freecodecamp', 'storbeck', 'habathcx', 'RobotCaleb', 'noobs2ninjas'];
const twitchAPI = 'https://wind-bow.glitch.me/twitch-api/';
const chan = 'channels/';
const strm = 'streams/';

$(document).ready(function () {

    const $dropdown = $('#dropdown');
    const $dropdownContent = $('.dropdownContent');
    const btn = $('#hamWrap');
    const $expandAll = $('#expandAll');

    lockingDropdownMenu($dropdown, $dropdownContent, btn);
    
    if ($expandAll.is(':checked')) {
        $expandAll.prop('checked', false);
    }

    $expandAll.on('click', function () {
        if ($expandAll.is(':checked')) {
            $('.twitchLine').addClass('wide');
        } else {
            $('.twitchLine').removeClass('wide');
        }
    });

    $('input[type=radio]').on('click', function () {
        switch ($(this).val()) {
            case 'active':
                $('.offline').hide();
                $('.active').show();
                break;
            case 'offline':
                $('.active').hide();
                $('.offline').show();
                break;
            default:
                $('.twitchLine').css('display', 'grid');
        }
    });


    $('form').submit(function (event) {
        let search = ($('#searchField').val()).trim();
        if (search.length > 0) {
            let searchExp = new RegExp(search, 'i');
            $('.twitchLine:visible').each(function () {
                if (!searchExp.test($(this).attr('id'))) {
                    $(this).hide();
                }
            });
        }
        event.preventDefault();
    });
});

function addDiv(e) {
    $('.container').append(e)
}

function createTwitchLine(strmObj) {
    let status;
    if (strmObj.status === 'offline') {
        status = 'offline';
    } else {
        status = 'active';
    }
    return '<div class="twitchLine ' + status + '" id="' + strmObj.userID + '"><div class="logo"><img src="' +
        strmObj.logoUrl + '" alt="stream logo" height="75" width="75"></div><div class="streamName"><a href="' +
        strmObj.url + '" target="_blank">' +
        strmObj.name + '</a></div><div class="streamDesc">' +
        strmObj.status + '</div></div>';
}

async function fetchStreamData(user) {
    const responseChan = await fetch(twitchAPI + chan + user);
    const chanData = await responseChan.json();
    const responseStrm = await fetch(twitchAPI + strm + user);
    const strmData = await responseStrm.json();
    let chanStatus;
    if (strmData.stream) {
        chanStatus = strmData.stream.channel.status;
    } else {
        chanStatus = 'offline';
    }
    return {
        userID: user,
        name: chanData.display_name,
        logoUrl: chanData.logo,
        url: chanData.url,
        status: chanStatus
    }
}

function parseStreams(userArray) {
    return Promise.all(userArray.map(function (stream) {
        return fetchStreamData(stream);
    }))
}

async function init() {
    line = await parseStreams(streams);
    lineHTML = await line.map(x => createTwitchLine(x));
    addDiv(lineHTML);
}

function lockingDropdownMenu(e, content, btn) {

    /** REQUIRES jQuery
        'e' -- element to add hover event to
        'content' -- hidden content of dropdown menu
        'btn' -- button to toggle lock on dropdown menu */

    const $list = $('.dropdownContent li');
    const btnOffset = btn.offset();
    const listLength = $list.length;
    let speed = 600;
    const speedOffset = 100;
    const slideSpeed = speed - ((listLength - 1) * speedOffset);

    //Hamburger Menu START
    const $hbTop = $('#hbTop');
    const $hbMiddle = $('#hbMiddle');
    const $hbBottom = $('#hbBottom');
    //Hamburger Menu END

    addHoverEvent(e, content);

    btn.click(function () {
        $hbTop.toggleClass('hbTopX');
        $hbMiddle.toggleClass('hbMiddleX');
        $hbBottom.toggleClass('hbBottomX');
        if (e.hasClass('hasEvent')) {
            e.off("mouseenter mouseleave");
            e.removeClass('hasEvent');
        } else {
            addHoverEvent(e, content);
        }
    });

    function addHoverEvent(e, content) {
        e.hover(function () {
            e.addClass('hasEvent');
            content.slideDown(slideSpeed);
            $list.each(function () {
                $(this).offset({ top: btnOffset.top });
                $(this).animate({
                    top: 0
                }, speed);
                speed -= speedOffset;
            });
        }, function () {
            content.slideUp(slideSpeed);
            $list.each(function () {
                $(this).animate({
                    top: btnOffset.top - $(this).offset().top
                }, speed);
                speed += speedOffset;
            });
        });
    }
}

init();
            
          
!
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