diff --git a/base.css b/base.css index 3b72264..f981be6 100644 --- a/base.css +++ b/base.css @@ -8,6 +8,16 @@ body { font-family: "Lato", sans-serif; } +#moveTop{ + position: fixed; + right: 10px; + bottom:20px; + width: 20px; + height:20px; + + /*background: url(http://www.clker.com/cliparts/w/B/n/x/j/A/arrow-orange-md.png); */ +} + #wrapper { display: flex; justify-content: space-between; diff --git a/index.html b/index.html index 8c6878e..681b914 100644 --- a/index.html +++ b/index.html @@ -131,7 +131,7 @@

Variables

var a = 42; //holding number
- var b = "Awesomenes" //holding string + var b = "Awesomeness" //holding string

Scope of Variables @@ -141,7 +141,7 @@

Global Variables
They are declared outside functions and can be accessed anywhere inside JS code.
-
Local Vaariables
+
Local Variables
They are declared inside functions and don't exist outside the functions. You will be reading about the JS functions in a later section.

@@ -689,7 +689,7 @@

Closures

NOTE: Read this page very very carefully. The topic covered is the heart of Object Oriented Programming using JS.

- The local variables inside the funtions are recreated each time a function is called and these are independent of each other. Normally, in other languages when any function exits, the local variables are destroyed. JS has the ability to store functions as variables under some circumstances. Since functions can be stored in variable names like: + The local variables inside the functions are recreated each time a function is called and these are independent of each other. Normally, in other languages when any function exits, the local variables are destroyed. JS has the ability to store functions as variables under some circumstances. Since functions can be stored in variable names like:

var fun = function(){ //function Code @@ -864,5 +864,48 @@ <h3 class="heading">Prototypes</h3> </div> </div> </div> + +<input type="image" id="moveTop" src="http://www.clker.com/cliparts/w/B/n/x/j/A/arrow-orange-md.png"></input> + </body> +<script type="text/javascript"> +var moveToTopLibrary = function(idOfButton, time, frequency){ + var moveToTopButton = document.getElementById(idOfButton); + + var intervalId; + + window.addEventListener('wheel', function(event){ + if(intervalId!=null && event.deltaY > 0){ + clearInterval(intervalId); + } + }); + + var moveToTop = function(event){ + console.log(this); + console.log("moveToTop was called"); + + + var currentY = window.scrollY; + + + var delta = currentY / (time/frequency); + if(intervalId != null){ + clearInterval(intervalId); + } + intervalId = setInterval(function(){ + + window.scrollTo(window.scrollX, window.scrollY - delta); + + if(window.scrollY == 0){ + clearInterval(intervalId); + } + + },frequency); + + }; + moveToTopButton.addEventListener('click', moveToTop); +}; + +moveToTopLibrary('moveTop', 2000, 10); +</script> </html> \ No newline at end of file diff --git a/menu.js b/menu.js index 67a19e5..d902e80 100644 --- a/menu.js +++ b/menu.js @@ -156,4 +156,6 @@ window.onload = function() { } } } -} \ No newline at end of file +} + +