javascript - I have a jQuery code where opacity goes up as cursor goes down. How do I reverse it? -


    $(function() {          var $win = $(window),              h = 0,              opacity = 0,              getwidth = function() {                  h = $win.height();              };                $win.mousemove(function(e) {              getwidth();              opacity = (e.pagey / h);              console.log(opacity);              $('#myelement').css('opacity', opacity);          });      });
     #myelement {           height: 100px;           width: 100px;           background-color: blue;       }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div id="myelement"></div>

http://jsfiddle.net/wv8jx/791/

when mouse goes down, element shows. want same thing except want element disappear scroll down, instead of showing up. ideas how that?

since opacity attribute can have value between 0 , 1, can reverse behavior simple changing following line:

opacity = (e.pagey/h);

to like:

opacity = 1 - (e.pagey/h);

you can check working example here


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -