JavaScript
x
13
13
1
jQuery(window).scroll(function(){
2
if (jQuery(this).scrollTop() > 100) {
3
jQuery('#topcontrol').css({bottom:"15px"});
4
} else {
5
jQuery('#topcontrol').css({bottom:"-100px"});
6
}
7
});
8
9
jQuery('#topcontrol').click(function(){
10
jQuery('html, body').animate({scrollTop: '0px'}, 800);
11
console.log('works');
12
});
13
Nothing happens. No errors in the console are shown. No matter what event – click, hover, etc – they only work if I apply them to the ‘html’ tag. First part of the code works perfectly, I mean the .css.
What kind of sorcery is this?
Advertisement
Answer
Grrr… I figured it out. The whole code needs to be included within this:
JavaScript
1
4
1
$( document ).ready(function() {
2
console.log( "ready!" );
3
});
4
Can anyone provide an explanation on this? Some images were not found, can that influence this?