LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code



CSS
body
{
  background-color: grey;
}

#container
{
  background-color: black;
  color: white;
  width: 50%;
  text-align: center;
}
/* Dropdown Button */
.dropbtn {
    background-color: #4CAF50;
    color: white;
    padding: 16px;
    font-size: 16px;
    border: none;
    cursor: pointer;
}

.dropbtn:hover, .dropbtn:focus {
    background-color: #3e8e41;
}

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    overflow: auto;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
}

.dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
}

.dropdown a:hover {background-color: #f1f1f1}

.show {display:block;}
JS
var Coin = "btc"; //Bitcoin by default
var text = "Bitcoin"
var display = document.getElementById("container");

var notification = Notification; // Notifications are not working on codepen. Immediately denied.

console.log(notification.permission);
function requestDesktopNotificationPermission()
{
 
   notification.requestPermission(function (permission) {
      if(!('permission' in notification)) {
        notification.permission = permission;
      }
   });
 }
function selectedCoin(coin) // When a menu item is selected.
{
  let redo = false;
  switch(coin) // choooses the coin to show based on the parameter given.
         {
           
           case 'btc':
             Coin = 'BTC';
             text = 'Bitcoin';
             redo = true;
             break;
           case 'eth':
             Coin = 'ETH';
             text = 'Ethereum';
             redo = true;
             break;
           case 'zec':
             Coin = 'ZEC';
             text = 'ZCash';
             redo = true;
             break;
           default:
             Coin = 'BTC';
             text = 'Bitcoin';
             redo = true;
             break;
           
         }
  if(redo)
    {
      redo = false;
      $.getJSON("https://min-api.cryptocompare.com/data/price?fsym=" + Coin +"&tsyms=USD")
        .done(format);
    }
}

Coin = Coin.toUpperCase();
selectedCoin();

function format(response)
{
  display.innerHTML = "1 " + text + " = $" + JSON.stringify(response.USD);
}

/* When the user clicks on the button, 
toggle between hiding and showing the dropdown content */
function myFunction() {
    document.getElementById("myDropdown").classList.toggle("show");
}

// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
  if (!event.target.matches('.dropbtn')) {

    var dropdowns = document.getElementsByClassName("dropdown-content");
    var i;
    for (i = 0; i < dropdowns.length; i++) {
      var openDropdown = dropdowns[i];
      if (openDropdown.classList.contains('show')) {
        openDropdown.classList.remove('show'); // if menu is already present remove it.
      }
    }
  }
}

Description

Learning the crytpo compare api to make an alert app for those invested.
Term
Wed, 12/27/2017 - 07:06

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv