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.

            
              <!DOCTYPE html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Blackout Poetry</title>
</head>
<body>
  <div class="menu">
    <p>Click a word mark it. </p>
    <div class="btn blockOut">blockout/unblock unmarked words</div>
    <div class="btn clearMarked">clear marked words</div>
    <div class="btn reset">Reset all words</div>
  </div>

  <h3>Instructions: </h3>
  <div class="info">
    <p>A blackout poem is made by selecting indivual words from a longer story.</p>

    <p>In the Story Snippet below, clicking individual words marks them in yellow and adds them to your poem in the order they appear.</p>

    <p>"block/unblock unmarked words" will block out all words that are not marked in yellow.</p>

    <p>Use the existing story below or copy and paste your own story into the window below and hit submit.</p>

  </div>
  <div class="upload">
    <form class="upload" onSubmit="return newStory();">
      <textarea class="textarea"></textarea>
      <input type="submit" value="Submit">
    </form>
  </div>

  <h3>Story Snippet: (click words to mark)</h3>
  <div class="story">
  </div>
  <h3>Your Poem:</h3>
  <div class="poem">(Marks words above to populate your poem)
  </div>

</body>
            
          
!
            
              body {
  padding: 1em;
}

.poem {
  font-size: 30px;
}

.blocked {
  background-color: #222222;
  transition: background-color 0.5s ease-in-out;
  transition: opacity 0.5s ease-in-out;
  border-radius: 8px;
}


.faded {
  opacity: .0;
  transition: opacity 0.5s   ease-in-out;
  border-radius: 8px;
}

span {
  opacity: 1;
  transition: opacity 0.5s   ease-in-out;
  transition: background 0.5s   ease-in-out;
  border-radius: 8px;
}

div {  max-width: 1000px;}

.story {
  font-size:20px;
  margin-top:40px;

}



h3{
  padding-top:5em;
}

div.menu{
  position: fixed;
  top: 10px;
  background: #CCCCCC;
  padding: 3px;
  border: 1px solid black;
  z-index: 5;

}

.marked {
  background-color: yellow;
}
.btn {
  border-radius: 8px;
  background: #FFFFFF;
  display: inline-block;
  vertical-align: middle;
  
  
  margin: 4px 4px 4px 4px;
  padding: 5px 5px 5px 5px;
}

.reset { background: red; }

.active{
  background: yellow;
}

            
          
!
            
              
var story = "I had scarcely thought of the theater for some years, when Kean arrived in this country; and it was more from curiosity than from any other motive, that I went to see, for the first time, the great actor of the age. I was soon lost to the recollection of being in a theater, or looking upon a great display of the \"mimic art.\" The simplicity, earnestness, and sincerity of his acting made me forgetful of the fiction, and bore me away with the power of reality and truth. If this be acting, said I, as I returned home, I may as well make the theater my school, and henceforward study nature at second hand. \nHow can I describe one who is almost as full of beauties as nature itself,—who grows upon us the more we become acquainted with him, and makes us sensible that the first time we saw him in any part, however much he may have moved us, we had but a partial apprehension of the many excellences of his acting? We cease to consider it as a mere amusement. It is an intellectual feast; and he who goes to it with a disposition and capacity to relish it, will receive from it more nourishment for his mind, than he would be likely to do in many other ways in twice the time. Our faculties are opened and enlivened by it; our reflections and recollections are of an elevated kind; and the voice which is sounding in our ears, long after we have left him, creates an inward harmony which is for our good. \nKean, in truth, stands very much in that relation to other players whom we have seen, that Shakspeare does to other dramatists. One player is called classical; another makes fine points here, and another there; Kean makes more fine points than all of them together; but in him these are only little prominences, showing their bright heads above a beautifully undulated surface. A continual change is going on in him, partaking of the nature of the varying scenes he is passing through, and the many thoughts and feelings which are shifting within him.";

//var penState = "off";
var blockedOut = false;
var faded = false;
var punctuation = /([—.,?!;:"'])/;


function displayStory(storytext){
  var poem = '';
  var array = storytext.split(' ');
  array.forEach(function(word){
    poem += "<span class>" + word + " </span>" 
  });
  $(".story").html(poem);
}

displayStory(story);









// Clicking on Words
$("div.story").on("click",function (evt){
  if (this === evt.target || $(evt.target).hasClass('faded') ){
  // do nothing
  } else {
      $(evt.target).removeClass("blocked")
      $(evt.target).toggleClass("marked")
  }
    updatePoem();
});



// Remove all classes, clear poem
$(".reset").on('click',function(){
  $("span").removeClass('blocked faded marked');
  $(".poem").html('(Marks words above to populate your poem)');
});


// Update text of poem
function updatePoem () {
  $("div.poem").html($("span.marked").text());
}

$(".toggleFade").on('click', function(){
  if (faded){
    unfade();
    faded = false;
  } else {
    fade();
    faded = true;
  }
});

function fadeUnfade(){
  $("span.blocked").addClass('faded')
  /*if (faded){
    unfade();
  } else {
    fade();
  }*/
}

function fade(){
  $("span.blocked").addClass('faded')
   faded = true;
}

function unfade(){
  $("span").removeClass('faded');
  faded = false;
}

// Block out all words not "marked"
$(".blockOut").on('click', function(){
  if(blockedOut){
    $("span:not('.marked')").removeClass("blocked");
    blockedOut = false;
  } else {
    $("span:not('.marked')").addClass("blocked");
    blockedOut = true;
  }
});

// 
$(".clearMarked").on('click', function(){
  
   $("span").removeClass("marked");
});

function newStory (){
  var storytext = $(".textarea").val()
  $('.story').html(displayStory(storytext));
  $(".textarea").val('');
  return false;
}


/*  Mouseover Behavior
$("div.story").on("mouseover",function (evt){
  
  if (this === evt.target || $(evt.target).hasClass("marked")){
    // do nothing
  } else {
    switch (penState){
      case "blocks":
        $(evt.target).addClass("blocked");
        break;
      case "clears":
        $(evt.target).removeClass("blocked");
        break;
    }
  }
  //updatePoem();
});

//Button, toggle mouseover behavior
$(".penState").on('click',function(){
  if ( penState === 'off' ){
    penState = 'blocks';
  } else if ( penState === 'blocks' ){
    penState = 'clears';  
  } else {
    penState = 'off';
  }
  $('.penState').text("Mouseover: " + penState);
});*/

            
          
!
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