Identify a specific part of the screen

Asked

Viewed 54 times

6

Is it possible for me to identify a specific part of the screen with Jquery’s javascript? For example when going through height y it perform a function for me? I imagine something like:

var minha_altura = $(window).height();
var altura       = 400;
if(minha_altura > 400) 
{
   //faz algo
}

The concept is correct and in fact it works?

1 answer

3


You can create an event in the window to detect mouse movement and with it his pageX/Y.

window.addEventListener('mousemove', function(event) {
  if(event.pageY > 400) {
    //{...}
  } else {
    //{...}
  }
});

Take an example:

window.addEventListener('mousemove', function(e) {
  document.body.innerHTML = '<p> PageY:'+e.pageY+'</p><p> PageX:'+e.pageX+'</p>';
});

  • thanks so much for the feedback, I could do this with the scroll of the page too?

  • 1

    @Marcoshenrique Claso that yes, in this way is possible. window.addEventListener('scroll', function() {&#xA;console.log(window.scrollY);&#xA;});

  • I appreciate the help, it was of great value

Browser other questions tagged

You are not signed in. Login or sign up in order to post.