5
I use the jQuery-Tools to create a custom effect scroll
in a div
as in the following example:
"use strict";
var id_label_ms = document.getElementById("count_label_ms");
var range = document.getElementById("area");
var cronometro = {};
var countms = 0;
var counterms;
var cronometroAtivo = false;
window.onload = function () {
areaMusica();
var scroll = $(".area");
$(":range").rangeinput({
onSlide: function(ev, step) {
scroll.css({left: -step});
},
progress: true,
change: function(e, i) {
scroll.animate({left: -i}, "fast");
},
speed: 0
});
};
function areaMusica(){
var k = 1; var tabela = '';
tabela = '<table id="table">';
for (var i = 0; i < 2; i++) {
if(i < 1){
tabela += '<tr class="containerFaixa">';
for (var j = 1; j < 62; j++) {
if(j == 1){
tabela += '<td class="faixa" style="min-width: 20px;">start</td>';
}else{
tabela += '<td class="container" id="td'+k+'"></td>';
k++;
}
}
tabela += '</tr>';
}else{
tabela += '<tr><td></td>';
for(var j = 1; j < 61; j++) {
if(j % 5 == 0){
tabela += '<td class="tempo" colspan="5">'+seconds2time((j*2)-10) +"min - "+seconds2time(j*2)+'min</td>';
}
}
tabela += '</tr>'
}
}
tabela += '</table>';
document.getElementById('area').innerHTML = tabela;
}
function seconds2time(seconds){
var minutes = Math.floor((seconds ) / 60);
var seconds = seconds - (minutes * 60);
var time = "";
if(minutes < 10){
minutes = "0"+minutes;
}
if(seconds == 0){
seconds = "0"+seconds;
}
time = minutes+":"+seconds;
return time;
}
function iniciar(elemento){
var icon = elemento.dataset.option;
range.style.left = 0;
if(icon === "play"){
start();
elemento.src = "http://cdn.flaticon.com/svg/70/70419.svg";
elemento.title = "Pausar";
elemento.dataset.option = "pause";
}else{
stop();
elemento.src = "http://cdn.flaticon.com/svg/70/70409.svg";
elemento.title = "Tocar";
elemento.dataset.option = "play";
}
}
function start() {
if (cronometroAtivo) return;
cronometroAtivo = true;
counterms = setInterval(function () {
range.style.left = range.style.left.substring(0, range.style.left.length-2) - 1;
countms = countms + 1;
id_label_ms.innerHTML = countms / 100 + " s";
}, 10);
};
function stop(){
range.style.left = 0;
cronometroAtivo = false;
countms = 0;
id_label_ms.innerHTML = countms + " s";
clearInterval(counterms);
cronometroAtivo = false;
};
.containerArea{
height: auto;
width: 1030px;
border: 1px rgb(89,89,89) solid;
margin-top: 30px;
background: rgb(173,234,234);
}
.slider {
position:absolute;
cursor:pointer;
height:1px;
border:2px solid rgb(179,179,179);
width:1000px;
-moz-border-radius:2px;
-webkit-border-radius:2px;
}
#scrollwrap {
margin-top:30px;
margin-left:10px;
overflow:hidden;
width: 1000px;
margin-left:5px;
height:auto;
}
.container{
min-width: 23px;
height: 26px;
border: 1px rgb(140, 173, 188) double;
}
.containerFaixa{
width: 1000px;
height: 26px;
border: 1px rgb(140, 173, 188) double;
background: rgb(216,216,191);
border-radius: 7px;
}
.faixa{
color: rgb(0, 0, 0);
text-align: center;
font-size: 12px;
font-weight: bold;
font-family: inherit;
font-style: inherit;
text-decoration: inherit;
text-align: center;
line-height: 1.85em;
}
.tempo{
color: rgb(0, 0, 0);
font-size: 10px;
font-weight: inherit;
font-family: 'Courier New', Courier, monospace;
font-style: inherit;
text-decoration: inherit;
}
.progress {
background-color:rgb(179,179,179);
height:3px;
position:absolute;
width:0;
}
.handle {
position: absolute;
z-index:4;
width: 28px;
height: 115px;
background-position: top center;
background-size: 25px 30px;
background-image: url(http://cdn.flaticon.com/svg/17/17736.svg);
background-repeat: no-repeat;
}
.area {
position:relative;
font:bold 90px sans-serif;
height:auto;
}
.range {
display:none;
}
<script src="http://cdn.jquerytools.org/1.2.6/full/jquery.tools.min.js"></script>
<body>
<input id="range" type="range" max="795" value="0" />
<div class="containerArea">
<div id="scrollwrap">
<div id="area" class="area"></div>
</div>
</div>
<table style="margin-top: 20px;">
<tr>
<td name="btStart"><img src="http://cdn.flaticon.com/svg/70/70409.svg" style="width: 30px;" onclick="iniciar(this)" data-option="play" title="Tocar" /></td>
</tr>
</table>
<div>
Count: <label id="count_label_ms"></label>
</div>
The intention is to create a custom audio player, when you click play, Handle starts to move along with Count. Each column of the table represents 2 seconds.
Problem 1: This example of mine works locally, but I couldn’t make it work online, both here on the Stack Snippets and on jsFiddle and as far as in the codeOpen. The count starts but Handle doesn’t start to move, I created a zip for those who want to test locally.
This is not even the main issue, but I would like to understand what is wrong so that in these online tools it does not work properly?
Problem 2: I know the constant speed of Handle should be: that is to say 2/24 = 0,0834
. So, theoretically in function start
the calculation should be:
range.style.left = range.style.left.substring(0, range.style.left.length-2) - 0,0834;
But it’s not moving properly, it’s moving very slowly, I tried to adjust for more and for less, but it always seems to stay either too slow, or too fast, it also affects problem 3.
Problem 3: I wish to make an Handle that can be customized locally if I change the style of Handle, as in the following example:
"use strict";
var id_label_ms = document.getElementById("count_label_ms");
var range = document.getElementById("area");
var cronometro = {};
var countms = 0;
var counterms;
var cronometroAtivo = false;
window.onload = function () {
areaMusica();
var scroll = $(".area");
$(":range").rangeinput({
onSlide: function(ev, step) {
scroll.css({left: -step});
},
progress: true,
change: function(e, i) {
scroll.animate({left: -i}, "fast");
},
speed: 0
});
};
function areaMusica(){
var k = 1; var tabela = '';
tabela = '<table id="table">';
for (var i = 0; i < 2; i++) {
if(i < 1){
tabela += '<tr class="containerFaixa">';
for (var j = 1; j < 62; j++) {
if(j == 1){
tabela += '<td class="faixa" style="min-width: 20px;">start</td>';
}else{
tabela += '<td class="container" id="td'+k+'"></td>';
k++;
}
}
tabela += '</tr>';
}else{
tabela += '<tr><td></td>';
for(var j = 1; j < 61; j++) {
if(j % 5 == 0){
tabela += '<td class="tempo" colspan="5">'+seconds2time((j*2)-10) +"min - "+seconds2time(j*2)+'min</td>';
}
}
tabela += '</tr>'
}
}
tabela += '</table>';
document.getElementById('area').innerHTML = tabela;
}
function seconds2time(seconds){
var minutes = Math.floor((seconds ) / 60);
var seconds = seconds - (minutes * 60);
var time = "";
if(minutes < 10){
minutes = "0"+minutes;
}
if(seconds == 0){
seconds = "0"+seconds;
}
time = minutes+":"+seconds;
return time;
}
function iniciar(elemento){
var icon = elemento.dataset.option;
range.style.left = 0;
if(icon === "play"){
start();
elemento.src = "http://cdn.flaticon.com/svg/70/70419.svg";
elemento.title = "Pausar";
elemento.dataset.option = "pause";
}else{
stop();
elemento.src = "http://cdn.flaticon.com/svg/70/70409.svg";
elemento.title = "Tocar";
elemento.dataset.option = "play";
}
}
function start() {
if (cronometroAtivo) return;
cronometroAtivo = true;
counterms = setInterval(function () {
range.style.left = range.style.left.substring(0, range.style.left.length-2) - 1;
countms = countms + 1;
id_label_ms.innerHTML = countms / 100 + " s";
}, 10);
};
function stop(){
range.style.left = 0;
cronometroAtivo = false;
countms = 0;
id_label_ms.innerHTML = countms + " s";
clearInterval(counterms);
cronometroAtivo = false;
};
.containerArea{
height: auto;
width: 1030px;
border: 1px rgb(89,89,89) solid;
margin-top: 30px;
background: rgb(173,234,234);
}
.slider {
position:absolute;
cursor:pointer;
height:1px;
border:2px solid rgb(179,179,179);
width:1000px;
-moz-border-radius:2px;
-webkit-border-radius:2px;
}
#scrollwrap {
margin-top:30px;
margin-left:10px;
overflow:hidden;
width: 1000px;
margin-left:5px;
height:auto;
}
.container{
min-width: 23px;
height: 26px;
border: 1px rgb(140, 173, 188) double;
}
.containerFaixa{
width: 1000px;
height: 26px;
border: 1px rgb(140, 173, 188) double;
background: rgb(216,216,191);
border-radius: 7px;
}
.faixa{
color: rgb(0, 0, 0);
text-align: center;
font-size: 12px;
font-weight: bold;
font-family: inherit;
font-style: inherit;
text-decoration: inherit;
text-align: center;
line-height: 1.85em;
}
.tempo{
color: rgb(0, 0, 0);
font-size: 10px;
font-weight: inherit;
font-family: 'Courier New', Courier, monospace;
font-style: inherit;
text-decoration: inherit;
}
.progress {
background-color:rgb(179,179,179);
height:3px;
position:absolute;
width:0;
}
.handle {
position: absolute;
z-index:4;
width: 28px;
height: 55px;
border: rgb(161, 233, 240) solid;
background-position: top center;
background-size: 25px 30px;
background-image: url(http://cdn.flaticon.com/svg/17/17736.svg);
background-repeat: no-repeat;
box-shadow: 0px 0px 0px 1px rgb(0, 0, 0),inset 0px 0px 0px 1px rgb(0, 0, 0);
}
.area {
position:relative;
font:bold 90px sans-serif;
height:auto;
}
.range {
display:none;
}
<script src="http://cdn.jquerytools.org/1.2.6/full/jquery.tools.min.js"></script>
<body>
<input id="range" type="range" max="795" value="0" />
<div class="containerArea">
<div id="scrollwrap">
<div id="area" class="area"></div>
</div>
</div>
<table style="margin-top: 20px;">
<tr>
<td name="btStart"><img src="http://cdn.flaticon.com/svg/70/70409.svg" style="width: 30px;" onclick="iniciar(this)" data-option="play" title="Tocar" /></td>
</tr>
</table>
<div>
Count: <label id="count_label_ms"></label>
</div>
The time of Handle movement when clicking the button start
gets weird and apparently gets faster when there is no change in function:
function start() {
if (cronometroAtivo) return;
cronometroAtivo = true;
counterms = setInterval(function () {
range.style.left = range.style.left.substring(0, range.style.left.length-2) - 1;
countms = countms + 1;
id_label_ms.innerHTML = countms / 100 + " s";
}, 10);
};
I can help you, for 50 points to solve 1 of the 3 problems...rsrssr can even choose which one you want to solve, if the reward is 150 solve the 3 problems, jokes aside, you could open 3 questions right, so that it is not so broad the answers.
– SneepS NinjA
So @Sneepsninja, except for problem 1, which is more a curiosity itself, the other 2 problems I have a feeling that are intrinsically linked, I thought it best to put everything in a question only, but I do not know, if it is necessary I share them
– MarceloBoni
concerning problem 3, could use jQuery, put a button to change the theme and make a simple exchange of classes between the html elements is something very simple, I think it is not worth an answer, a comment I think already gives p/ understand a look there https://jqueryui.com/toggleClass/
– SneepS NinjA