Jquery Scrolltop() event in meteor


#1

Hello
I have a problem with jquery ScrollTop() function it’s not working in meteor.
I am trying to implement next code:

jQuery(window).scroll(function(){
if (jQuery(document).scrollTop() > 350 ) {
alert(“Fuck yeah!”)
}
});
How to do it workable?


#2
$(window).scroll(function() {
    if ( $(".something").length ) {
      var nav = $(".something");

      if ( $(window).scrollTop() >= 200 ) {
        nav.addClass("active");
      } else
        nav.removeClass("active");
    }
});

our class=“something” element is anchor navigation, which switch to position: fixed when scrolling
lenght is there to be kinda active only on sites where is anchor navigation element.


#3

I just need to show some div when I scroll to 350px, is it possible?


#4

yes, what you describe is possible


#5

Could you show me how to do that?
I did it with next code, but that’s not work:

Template.main.onRendered(function () {
$(window).scroll(function() {
if ( $(window).scrollTop() > 350 ) {
$(".block").show();
}
else{
$(".block").hide();
}
});


#6

your code should work. But we did not attach it to some Main template, as we have no such template.
We let it as pure JS to be loaded by Meteor by default.


#7

Look, I have a main template and when I scroll to some div it have to be visible.
When I write code not inside of main template, it’s still not working, in the bottom is print screen of that

I can’t understand, why that’s still not working


#8

I dont see any issue in that code, only thing I can think of is wring selector for that free-table…
In which case it would not execute ofc.


#9

if I give you link on my meteor project, will you help me?


#10

probably not, but some1 maybe could


#11

I just made a meteorpad with your code

http://meteorpad.com/pad/hfewRpWNMiL2Q7upe/quickHack-scrollTop

it worked, so must be something else with your app