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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <span id="currentRiverStatus"></span>
<span id="RiverLevelsTable">
  <h3>Latest Readings</h3>
<table id="RLTable" class="tablepress">
  <thead>
    <tr>
      <th>Date</th>
      <th>Time</th>
      <th>Reading</th>
    </tr>
  </thead>
  <tbody>
    
  </tbody>
  </table>
</span>


            
          
!
            
              * {
  font-family: sans-serif;
}

h3 {
  color:#89006b;
}

thead {
  color:white;
  background-color:#89006b;
  th {
    padding:10px;
    }
}

tbody {
  color:#89006b;
  td {
    padding: 5px 10px;
    text-align: right;
  }
  .odd {
   background-color:#e8eaed;
  }
}
            
          
!
            
              // Work in progress to pull the river level api used by the environment agency in the UK.

// This has been developed for the www.ycrc.co.uk website

// Uses the jquery json parser

// Function to get json from environment agency and then publish into html

var environmentJSON;
$.getJSON("https://environment.data.gov.uk/flood-monitoring/id/measures/L2406-level-stage-i-15_min-m/readings?_sorted&_limit=500", function(json){
    environmentJSON = json;
  
  // collect current reading
  var currentReading = json["items"][0]["value"];

  // collect previous reading
    var previousReading = json["items"][1]["value"];
  
  // decides whether the river is falling, rising or level
  
  if (currentReading > previousReading) {
    var riverStatus = 'rising';
  } else if (currentReading < previousReading) {
    var riverStatus = 'falling';
  } else {
    var riverStatus = 'static';
  }
  
  // works out where the river is in relation to the steps & also what boats can go out on the river
  
  if (currentReading > 4.17) {
    var riverPosition = 'River is in the boathouse';
    var crewBoats = 'No boats should be out on the water.';
  } else if (currentReading > 4.00) {
    var riverPosition = 'The river is on the road';
    var crewBoats = 'No boats should be out on the water.';
  } else if (currentReading > 3.87) {
    var riverPosition = 'The river is on the top step';
    var crewBoats = 'No boats should be out on the water.';
  } else if (currentReading > 3.77) {
    var riverPosition = 'The river is 1 step from the road';
    var crewBoats = 'No boats should be out on the water.';
  } else if (currentReading > 3.68) {
    var riverPosition = 'The river is 2 steps from the road';
    var crewBoats = 'No boats should be out on the water.';
  } else if (currentReading > 3.52) {
    var riverPosition = 'The river is 3 steps from the road';
    var crewBoats = 'No boats should be out on the water.';
  } else if (currentReading > 3.39) {
    var riverPosition = 'The river is 4 steps from the road';
    var crewBoats = 'No boats should be out on the water.';
  } else if (currentReading > 3.23) {
    var riverPosition = 'The river is 5 steps from the road';
    var crewBoats = 'No boats should be out on the water.';
  } else if (currentReading > 3.07) {
    var riverPosition = 'The river is 6 steps from the road';
    var crewBoats = 'Only senior boats during the day can be out on the water.';
  } else if (currentReading > 2.91) {
    var riverPosition = 'The river is 7 steps from the road';
    var crewBoats = 'Only senior boats during the day can be out on the water.';
  } else if (currentReading > 2.75) {
    var riverPosition = 'The river is 11 steps above the tow-path';
  } else if (currentReading > 2.59) {
var riverPosition = 'The river is 10 steps above the tow-path';
  } else if (currentReading > 2.43) {
    var riverPosition = 'The river is 9 steps above the tow-path';
  } else if (currentReading > 2.27) {
    var riverPosition = 'The river is 8 steps above the tow-path';
  } else if (currentReading > 2.11) {
    var riverPosition = 'The river is 7 steps above the tow-path';
  } else if (currentReading > 1.95) {
    var riverPosition = 'The river is 6 steps above the tow-path';
  } else if (currentReading > 1.79) {
    var riverPosition = 'The river is 5 steps above the tow-path';
  } else if (currentReading > 1.63) {
    var riverPosition = 'The river is 4 steps above the tow-path';
  } else if (currentReading > 1.47) {
    var riverPosition = 'The river is 3 steps above the tow-path';
  } else if (currentReading > 1.31) {
    var riverPosition = 'The river is 2 steps above the tow-path';
  } else if (currentReading > 1.15) {
    var riverPosition = 'The river is 1 step above the tow-path';
  } else if (currentReading > 1.06) {
    var riverPosition = 'The river is level just over the towpath';
  } else if (currentReading > 0.95) {
    var riverPosition = 'The river is level with the towpath';
    var crewBoats = 'No boat restrictions at this time.';
  } else if (currentReading > 0.75) {
    var riverPosition = 'The river is 1 step below the towpath';
    var crewBoats = 'No boat restrictions at this time.';
  } else if (currentReading > 0.60) {
    var riverPosition = 'The river is 2 steps below the towpath';
    var crewBoats = 'No boat restrictions at this time.';
  } else if (currentReading > 0.40) {
    var riverPosition = 'The river is 3 steps below the towpath';
    var crewBoats = 'No boat restrictions at this time.';
  } else if (currentReading > 0.20) {
    var riverPosition = 'The river is 4 steps below the towpath';
    var crewBoats = 'No boat restrictions at this time.';
  } else if (currentReading < 0.21) {
    var riverPosition = 'The river is over 4 steps below the towpath';
    var crewBoats = 'No boat restrictions at this time.';
  }
  
  // populates the html with the currentReading and also riverPosition and riverStatus. depending on if the crewBoats variable is set, this information is also included
 
  if (crewBoats) {
    document.getElementById('currentRiverStatus').innerHTML = '<p>' + 'The latest river level is ' + currentReading + ' m and was taken at  ' + json["items"][0]["dateTime"].substring(11,16) + '. ' + riverPosition + ' and is currently ' + riverStatus + '.' + '</p>' + '<p> Current recommendation: ' + crewBoats + '</p>';
  } else {
      document.getElementById('currentRiverStatus').innerHTML = '<p>' + 'The latest river level is ' + currentReading + ' m and was taken at  ' + json["items"][0]["dateTime"].substring(11,16) + '. ' + riverPosition + ' and is currently ' + riverStatus + '.' + '</p>';
  }
  
  // table with sets of readings. We'll want.....
  // Date(split from dateTime value)  Time(split from dateTime value)  Reading
 
  // gets the table already in the html
  var table = document.getElementById("RLTable").getElementsByTagName('tbody')[0];
  
// sets the number of rows to be added
for (var row = 1; row < 6; row++) {
  var addrow = table.insertRow();
  
  // adds odd and even class to each row
  if (row % 2 == 0) {
    addrow.className = 'row-' + row + ' even';
  } else {
    addrow.className = 'row-' + row + ' odd';
  }
  
  //add three cells required to each row 
  var dateCell = addrow.insertCell(0);
  var timeCell = addrow.insertCell(1);
  var valueCell = addrow.insertCell(2);
  
  //adds the content from the river level API to each cell in the row
  dateCell.innerHTML = json["items"][row - 1]["dateTime"].substring(0,10);
  timeCell.innerHTML = json["items"][row - 1]["dateTime"].substring(11,16);
  valueCell.innerHTML = json["items"][row - 1]["value"] + ' m';
}
  
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console