Skip to content

Instantly share code, notes, and snippets.

@kebman
Last active September 16, 2018 22:02
Show Gist options
  • Save kebman/8741b44a647236b6e5f57a4594cb12ae to your computer and use it in GitHub Desktop.
Save kebman/8741b44a647236b6e5f57a4594cb12ae to your computer and use it in GitHub Desktop.
USD/NOK Currency Slider in HTML5
<!DOCTYPE html>
<html>
<head>
<title>USD/NOK Slider</title>
<meta charset="utf-8">
<style type="text/css">
.slidecontainer {
width: 20em; /* Width of the outside container */
}
/* Slider */
.slider {
-webkit-appearance: none; /* Override default CSS styles */
appearance: none;
width: 100%; /* Full-width */
height: 25px; /* Specified height */
background: #d3d3d3; /* Grey background */
outline: none; /* Remove outline */
opacity: 0.7; /* Set transparency (for mouse-over effects on hover) */
-webkit-transition: .2s; /* 0.2 seconds transition on hover */
transition: opacity .2s;
}
/* Mouse-over effects */
.slider:hover {
opacity: 1; /* Fully shown on mouse-over */
}
/* The slider handle (use -webkit- (Chrome, Opera, Safari, Edge) and -moz- (Firefox) to override default look) */
.slider::-webkit-slider-thumb {
-webkit-appearance: none; /* Override default look */
appearance: none;
width: 25px; /* Set a specific slider handle width */
height: 25px; /* Slider handle height */
background: #4CAF50; /* Green background */
cursor: pointer; /* Cursor on hover */
}
.slider::-moz-range-thumb {
width: 25px; /* Set a specific slider handle width */
height: 25px; /* Slider handle height */
background: #4CAF50; /* Green background */
cursor: pointer; /* Cursor on hover */
}
</style>
</head>
<body>
<header>
<h1>USD/NOK</h1>
</header>
<section>
<article>
<h1>$ → Kr. Slider</h1>
<div class="slidecontainer">
<input type="range" min="400" max="1000" value="825" class="slider" id="myRange">
</div>
<p>USDNOK: <span id="usdnok"></span></p>
<p>NOK 100.00 = USD <span id="usd"></span></p>
<p>USD 10.00 = NOK <span id="nok"></span> </p>
</article>
</section>
<footer></footer>
</body>
</html>
<script type="text/javascript">
const slider = document.getElementById("myRange");
const usdnok = document.getElementById("usdnok");
const usd = document.getElementById("usd");
const nok = document.getElementById("nok");
const acc = 100;
usdnok.innerHTML = slider.value;
console.log();
usdnok.innerHTML = (slider.value/acc).toFixed(2);
usd.innerHTML = (100/(slider.value/acc)).toFixed(2);
nok.innerHTML = (10*(slider.value/acc)).toFixed(2);
slider.oninput = function() {
let sval = (this.value/acc).toFixed(2);
usdnok.innerHTML = sval;
usd.innerHTML = (100/sval).toFixed(2);
nok.innerHTML = (10*sval).toFixed(2);
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment