I think something closer would be like below, but I would need to know more details about why you need this code.
window.addEventListener('load', function () {
document.querySelector("#table").addEventListener('scroll', function() {
if (this.scrollTop + this.offsetHeight == this.scrollHeight) {
console.log('final')
}
});
})
Just a small fix: jQuery is Javascript, not a language. In this case, you are not "converting to javascript", but using pure Javascript without the library.
I made a better example to check:
window.addEventListener('load', function () {
document.querySelector("#table").addEventListener('scroll', function() {
if (Math.ceil(this.scrollTop) + this.offsetHeight == this.scrollHeight) {
console.log('final')
}
});
})
#table{
max-height: 150px;
background-color: #ddd;
overflow: auto;
}
<div id="table">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
</div>
To do this without jQuery would be somewhat laborious and complicated, although perfectly possible. Wouldn’t rather learn how jQuery works rather than how you would eliminate it?
– Victor Stafusa
I can’t use framework, I have to use pure javascript
– Giovanni Estevam
I believe that someone will answer the question to you, but more importantly to have an answer to this, I will warn you: If you use jQuery, and do not know how to do with Javascript, I believe this is a problem.
– Wallace Maxters
You know what this code is doing?
– Wallace Maxters
The code will become much more complicated and difficult to understand if you do not use Jquery. One of Jquery’s main objectives is to simplify the selection of DOM elements, which is complicated. See this article: https://code.tutsplus.com/tutorials/from-jquery-to-javascript-a-reference-net-23703
– William John Adam Trindade
@Williamjohnadamtrinity on this I disagree. It’s been a while since jQuery is just about simplifying things. My answer for example, I spent the same amount of lines to do something similar.
– Wallace Maxters
@Wallacemaxters "jQuery is just to simplify things" it’s been a while since :) it doesn’t do anything that pure javascript doesn’t do, but anyway, simplifying is enough is not even?
– Ricardo Pontual
As @Wallacemaxters commented, if you don’t know what the code does, it’s not an aid to convert the code, but rather, "convert that code to me," and even
javascript
pure will continue without understanding, it would be cool to debug and see what each part does, so you’ll probably be able to convert next time :)– Ricardo Pontual
@Wallacemaxters What was the reason for creating Jquery? It is a library written in JS to simplify scritps written in JS (a bit redundant, but that’s what it is). You will tell me that Document.getElementById( 'Test' ).value = 5; it is simpler than $( '#Test' ).val( 5 ); ?
– William John Adam Trindade
@Giovanniestevam Jquery is not a framework. It is a library. And no, it is not the same.
– William John Adam Trindade
Anyway, but you understand that you can survive without jQuery, right? The purpose of jQuery was really to facilitate, but I believe that Javascript has features that dispense many things nowadays. See here you don’t need jQuery :D
– Wallace Maxters
@Wallacemaxters Yes, for this instead of Jquery, use framewok Vanilla JS :) (I hope you understand the reference)
– William John Adam Trindade
@Williamjohnadamtrindade is here What is Vanilla?
– Wallace Maxters