Skip to content

Top button added and with smooth scroll functionality #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions base.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
49 changes: 46 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ <h3 class="explanationHeading">Variables</h3>
</p>
<div class="code">
var a = 42; //holding number <br>
var b = "Awesomenes" //holding string
var b = "Awesomeness" //holding string
</div>
<h3 class="explanationHeading">
Scope of Variables
Expand All @@ -141,7 +141,7 @@ <h3 class="explanationHeading">
<dl class="explanationText">
<dt>Global Variables</dt>
<dd>They are declared outside functions and can be accessed anywhere inside JS code.</dd>
<dt>Local Vaariables</dt>
<dt>Local Variables</dt>
<dd>They are declared inside functions and don't exist outside the functions. You will be reading about the JS functions in a later section.</dd>
</dl>
</p>
Expand Down Expand Up @@ -689,7 +689,7 @@ <h3 class="heading">Closures</h3>
<!-- Start writing from here -->
<p class="explanationNote"><em>NOTE: </em> Read this page very very carefully. The topic covered is the heart of Object Oriented Programming using JS.</p>
<p class="explanationText">
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:
</p>
<xmp class="code">var fun = function(){
//function Code
Expand Down Expand Up @@ -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>
4 changes: 3 additions & 1 deletion menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,6 @@ window.onload = function() {
}
}
}
}
}