-1

This is my code and i get "TypeError: $ is not a function".

I have copied straight from this tut: http://jsfiddle.net/livibetter/HV9HM/

this is the website im working on: http://www.vetlesen.no

function sticky_relocate() {
    var window_top = $(window).scrollTop();
    var div_top = $('#sticky-anchor').offset().top;
    if (window_top > div_top) {
        $('#sticky').addClass('stick');
        $('#sticky-anchor').height($('#sticky').outerHeight());
    } else {
        $('#sticky').removeClass('stick');
        $('#sticky-anchor').height(0);
    }
}

This is the error

$(function() {
    $(window).scroll(sticky_relocate);
    sticky_relocate();
});

-

var dir = 1;
var MIN_TOP = 200;
var MAX_TOP = 350;

function autoscroll() {
    var window_top = $(window).scrollTop() + dir;
    if (window_top >= MAX_TOP) {
        window_top = MAX_TOP;
        dir = -1;
    } else if (window_top <= MIN_TOP) {
        window_top = MIN_TOP;
        dir = 1;
    }
    $(window).scrollTop(window_top);
    window.setTimeout(autoscroll, 100);
}
Vetlesen
  • 3
  • 4

3 Answers3

1

It seems you are using Wordpress. In Wordpress jQuery.noConflict() is called on the jQuery file it includes (scroll to the bottom of the file it's including for jQuery to see this), which means $ doesn't work, but jQuery does.

If you dont want to be bothered to change the syntax you can use

let $ = jQuery.noConflict();
kemotoe
  • 1,730
  • 13
  • 27
0

This error defines you did not have your JQuery script loaded. Make sure you have added JQuery script to your web page.

imacoder
  • 166
  • 1
  • 11
0

You can try to write on top of your sticky.js

    var $ = jQuery;

Seems something wrong with your jquery initialization (jquery doesnt initialized the $ var in global space)

davojta
  • 307
  • 1
  • 10