8
On the website of W3schools they mention that the event takes place in 350 milliseconds:
Note: While dragging an element, the ondrag Event Fires Every 350 milliseconds.
Only that it varies this because if I drag an element and does not move itlo it will be fired faster or it will occur in a smaller amount of milliseconds now if I keep dragging and moving the element it will occur faster still and in an even smaller amount of milliseconds.
Example:
<!doctype html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#div1 {
width: 100px;
height: 100px;
border: 1px solid black;
}
</style>
</head>
<body>
<div id="div1" draggable="true"></div>
<p id="p1"></p>
<script>
let div1 = document.querySelector("#div1");
let count = 0;
div1.addEventListener("drag", function() {
let p1 = document.querySelector("#p1");
count ++;
p1.innerHTML = `A div está sendo arrastada: ${count}`;
});
</script>
</body>
</html>
Note in the example above if I drag the element and keep the mouse stopped the variable count
is incremented slower and if I keep dragging and moving the mouse the variable count
is incremented faster. Just to complement this also occurs with the event mousemove
. In how many milliseconds is called the event drag
or depends on whether or not shown in the example above?
I don’t think you’re gonna find an exact answer to that question, like,, "are exactly 291ms".. depends on the system (computer), rendering engine, perhaps of the other objects in the Document... just curiosity, because you need this value?
– Ricardo Pontual
I just want to know for myself, I’m a skeptical person, I don’t like to have a question and not know the answer, also because if someone else asks me the same thing I won’t know what to answer.
– marquinho
got it... I think there should not have a right and exact answer, When dragging has a processing, browser, computer, browser rendering engine"
– Ricardo Pontual
Thanks! for having answered at least I had an idea of why this occurs with this event. But then why W3schools have established a fixed value of milliseconds?
– marquinho
W3schools is not a very good source - has been worse, hj improved a little, but I prefer to consult the MDN, that says that the event is triggered "Every few Hundred milliseconds", ie it does not have an exact value, because it depends on several factors, as already mentioned above
– hkotsubo
Thank you! to all of you for having responded.
– marquinho