A Pen by Jorge Epuñan on CodePen.
Created
February 6, 2014 16:51
-
-
Save ginirsss/8848092 to your computer and use it in GitHub Desktop.
A Pen by Jorge Epuñan.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // para @ginirsss y su proyecto que necesita saber como crear eventos segun la posicion del mouse en el viewport. | |
| var semaforo = true; | |
| $('body').append('<p class="pixeles"></p><p class="porcentaje"></p><p class="debug"></p>'); | |
| // en pixeles | |
| $(window).on('resize load', function(){ | |
| var $altoVentana = $(window).height(); | |
| var $anchoVentana = $(window).width(); | |
| $('.pixeles').text('ventana: ancho: '+$anchoVentana+'px | alto: '+$altoVentana+'px'); | |
| }); | |
| // en porcentaje | |
| $(window).on('mousemove', function(e){ | |
| var $height = e.pageY - $(window).scrollTop(); | |
| var $width = e.pageX - $(window).scrollTop(); | |
| var $verticalVentana = Math.floor($height/($(window).height())*100); | |
| var $horizontalVentana = Math.floor($width/($(window).width())*100); | |
| $('.porcentaje').text('posicion del cursor: horizontal: '+$horizontalVentana+'% | vertical: '+$verticalVentana+'%'); | |
| if($horizontalVentana <= 30 && semaforo){ | |
| // aqui lo q quieras hacer | |
| $('.debug').text('menor a 30%'); | |
| semaforo=false; | |
| } | |
| if($horizontalVentana >= 31 && $horizontalVentana <= 69 && !semaforo) { | |
| // aqui lo q quieras hacer | |
| $('.debug').text('mayor a 31% y menor a 69%'); | |
| semaforo=true; | |
| } | |
| if($horizontalVentana >= 70 && semaforo){ | |
| // aqui lo q quieras hacer | |
| $('.debug').text('mayor a 70%'); | |
| semaforo=false; | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| body { | |
| background-color: #16a085; | |
| color: white; | |
| text-align: center; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment