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.

            
              <div id="contain">
  <canvas id="antennas"></canvas>
</div>
<div id="tv">
  <div id="screen">
    <div id="inner">
    </div>
  </div>
  <div id="buttons">
    <a href="#" target="_self"><button id="tweet"><i class="fa fa-twitter fa-lg" aria-hidden="true"></i>
</button></a>
    <button id="quote"><i class="fa fa-quote-left" aria-hidden="true"></i> <i class="fa fa-quote-right" aria-hidden="true"></i>

</button>
    <button id="power"><i class="fa fa-power-off fa-lg" aria-hidden="true"></i>
</button>
  </div>
</div>
<div id="table">
</div>
<canvas id="legs"></canvas>
<div id="floor">
</div>
            
          
!
            
              =font-border($one, $two, $three, $four)
  text-shadow: $one 0 0 #000000, $two 0 0 #000000, 0 $one 0 #000000, 0 $two 0 #000000, $three $three #000000, $four $four 0 #000000, $three $four 0 #000000, $four $three 0 #000000

.center
  display: block
  margin: auto
  
.main-text
  color: #ffffff
  font-family: Lobster, cursive

body
  background-color: lightgrey
  
  #tv
    @extend .center
    width: 600px
    height: 500px
    background-color: #000000
    border-radius: 5%
    margin-top: 300px

    
  #screen 
    @extend .center
    background-color: #24221c
    width: 500px
    height: 400px
    position: relative
    top: 50px
    border-radius: 1%
    
    #inner
      @extend .center
      @extend .main-text
      background-color: white
      background-repeat: no-repeat
      background-size: 100% 100%
      width: 0
      height: 0
      position: relative
      top: 200px
      text-align: center
      
      h1
        +font-border(3px, -3px, 2px, -2px)
        font-size: 90px
        padding-top: 23px
        
      p 
        +font-border(3px, -3px, 2px, -2px)
        font-family: cursive
        font-size: 35px
        margin-left: 15px
        margin-right: 15px
        margin-top: -50px
        
      span
        +font-border(3px, -3px, 2px, -2px)
        font-family: cursive
        font-size: 30px
     
  #contain
    text-align: center
    
    #antennas
      width: 600px
      height: 300px
      position: absolute
      top: 15px
      margin-left: -285px
      
  #table 
    @extend .center
    width: 500px
    height: 25px
    background-color: #874c18
    border-radius: 5px
        
  #legs
    @extend .center
    width: 500px
    height: 500px
    
  #floor 
    width: 100%
    height: 875px
    background-color: #4a4642
    margin-top: -167px
    margin-left: -8px
    margin-bottom: -8px
    padding-right: 16px
   
  #buttons 
    text-align: center
    margin-top: 58px
    
    button:hover
      background-color: #121211
    
    button 
      height: 30px
      width: 50px
      border-radius: 100%
      background-color: #000000
      color: white
      border-width: 1px
      border-style: solid
      border-color: #1b1c1b
      
    #power
      height: 35px
      width: 36px
      color: red
      position: relative
      left: 150px
      
    #tweet
      margin-left: 0px
      
      a
        color: white
    
    #quote
      margin-left: 15px
      
   
            
          
!
            
              $(document).ready(function() {
  var canvas,
    ctx,
    on = false,
    $power = $("#power"),
    $inner = $("#inner"),
    $h1,
    url =
      "https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1",
    tweet = 'https://twitter.com/intent/tweet?text=',
    $a = $("a"),
    quote = false,
    interval,
    message,
    $p,
    i,
    $span,
    typing,
    author
  ;
  drawAntennas();
  drawTable();

  $power.click(function() {
    $power.prop('disabled', true);
    window.setTimeout(function() {
      $power.prop('disabled', false);
    }, 250);
    if (on) {
      if(interval !== true) {
        clearInterval(interval);
        interval = true;
        typing = false;
      }
      $power.css({ color: "red" });
      on = false;
      $inner.html("");
      turnOff();
    } else {
      turnOn();
    }
  });

  $("#quote").click(function() {
    if (on && !typing) {
      $h1 = $('h1');
      $h1.fadeTo(750, 0);
      window.setTimeout(function() {
        interval = false;
        getQuote();
        window.setTimeout(function() {
          $h1.text("");
        }, 125);
      }, 650);
    }
  });

  $("#tweet").click(function() {
    if (on && quote)
      $a.attr(
        "href",
        tweet +
          message +
          '  Author: ' +
          author.slice(1)
      );
    });


  function getQuote() {
    $.ajax({
      url: url,
      cache: false,
      dataType: "json",
      success: function(data) {
        if(interval !== true) {
        if (data[0].content.length <= 120) {
          message = data[0].content;
          message = message.slice(3, message.length - 5).trim();
          if (!/[&<>]/.test(message)) {
            if (on && !typing) {
              if ($p.html() !== "") {
                $p.fadeTo(350, 0);
                $span.fadeTo(350, 0);
                window.setTimeout(function() {
                  $p.html("");
                  $span.html("");
                  $p.fadeTo(0, 1);
                  $span.fadeTo(0, 1);
                }, 350);
              }
              message = data[0].content;
              message = message.slice(3, message.length - 5).trim();
              message = '"' + message + '"';
              author = "-" + data[0].title;
              typing = true;
              window.setTimeout(function() {
                typeOut(message, author);
                $a.attr("target", "_blank");
                quote = true;
              }, 550);
            }
          } else getQuote();
        } else getQuote();
      }
     }
    });
  }

  function typeOut(string, author) {
    if (!interval) {
      i = 0;
      interval = setInterval(function() {
        $p.html($p.html() + string.charAt(i));
       i++;
        if (i === string.length) {
        clearInterval(interval);
        i = 0;
        window.setTimeout(function() {
          interval = setInterval(function() {
            $span.html($span.html() + author.charAt(i));
            i++;
            if (i === author.length) {
              clearInterval(interval);
              typing = false;
            }
          }, 50);
        }, 1250);
      }
    }, 50);
  }
  }
  function drawAntennas() {
    canvas = document.getElementById("antennas");
    ctx = canvas.getContext("2d");
    ctx.beginPath(); // draw left antenna
    ctx.moveTo(50, 10);
    ctx.lineTo(120, 300);
    ctx.lineTo(135, 300);
    ctx.fill();
    ctx.beginPath(); // draw right antenna
    ctx.moveTo(295, 10);
    ctx.lineTo(115, 300);
    ctx.lineTo(135, 300);
    ctx.fill();
    ctx.beginPath(); // draw left antenna tip
    ctx.arc(53, 18, 6, 0, 2 * Math.PI);
    ctx.stroke();
    ctx.fill();
    ctx.beginPath(); // draw right atenna tip
    ctx.arc(290, 15, 7, 0, 2 * Math.PI);
    ctx.stroke();
    ctx.fill();
    ctx.beginPath(); // draw body
    ctx.ellipse(146, 156, 85, 40, 0, 0, 7);
    ctx.stroke();
    ctx.fill();
  }

  function drawTable() {
    canvas = document.getElementById("legs");
    ctx = canvas.getContext("2d");
    ctx.strokeStyle = "#874c18";
    ctx.fillStyle = "#874c18";
    ctx.beginPath(); // draw left leg
    ctx.moveTo(75, 0);
    ctx.lineTo(0, 100);
    ctx.lineTo(15, 100);
    ctx.lineTo(90, 0);
    ctx.stroke();
    ctx.fill();
    ctx.beginPath(); // draw right leg
    ctx.moveTo(225, 0);
    ctx.lineTo(300, 100);
    ctx.lineTo(285, 100);
    ctx.lineTo(210, 0);
    ctx.stroke();
    ctx.fill();
  }

  function turnOn() {
    $power.css({ color: "green" });
    on = true;
    $inner.animate({ width: "15%", height: "1px" }, 25);
    window.setTimeout(function() {
      $inner.animate({ width: "100%", height: "3px" }, 25);
      window.setTimeout(function() {
        $inner.animate({ height: "100%", top: "0px" }, 50);
        window.setTimeout(function() {
          showShow();
        }, 50);
      }, 25);
    }, 25);
  }

  function turnOff() {
    $power.css({ color: "red" });
    on = false;
    quote = false;
    $a.attr({
      href: "#",
      target: "_self"
    });
    hideShow();
    $inner.animate({ height: "3px", top: "200px" }, 50);
    window.setTimeout(function() {
      $inner.animate({ width: "15%", height: "1px" }, 25);
      window.setTimeout(function() {
        $inner.animate({ width: "0", height: "0" }, 25);
      }, 25);
    }, 25);
  }

  function showShow() {
    $inner.css({ "background-color": "#658bab" });
    $inner.css({
      "background-image": "url('http://bestanimations.com/Nature/clouds-flowing-over-lake-mountains-nature-animated-gif.gif')"
    });
    $inner.html("<h1>Random Quote Generator</h1><p></p><span></span>");
    $p = $("p");
    $span = $("span");
  }

  function hideShow() {
    $inner.css({ "background-color": "#ffffff" });
    $inner.css({ "background-image": "none" });
    $inner.html("");
  }
});

            
          
!
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