Using JavaScript and the WebViewer component we can create custom Sliders.
- We are going to create a "Slider Square" adapting these codes to App Inventor:
https://www.w3schools.com/howto/howto_js_rangeslider.asp
slider.htm
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.slidecontainer {
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #04AA6D;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
background: #04AA6D;
cursor: pointer;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
</head>
<body>
<div class="slidecontainer">
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
</div>
<script>
var slider = document.getElementById("myRange");
/// THIS LINE FOR CONTINUOUS CHANGE ////
slider.oninput = function() {window.AppInventor.setWebViewString("" + slider.value);}
///////////////////////////////////////////////////////////////////////////
/// THIS LINE FOR TOUCH UP ////
// slider.addEventListener('change', () => {window.AppInventor.setWebViewString("" + slider.value);});
///////////////////////////////////////////////////////////////////////////
</script>
</body>
</html>
p169C4i_javascript_deslizador.aia (2.6 KB)