Bououm Bououm - 23 days ago 14
Javascript Question

“TypeError: 'undefined' is not a function” when trying to add my custom css

I seriously cannot tell why Im having this problem each time I try to add my custom css file to the header.
Im using script called onepage-scroll.js
requires to put the file in the header

<script src="http://greenbex.com/js/onepagescroll.js"></script>
then write the code...
this is my header

<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="http://greenbex.com/css/onepage-scroll.css">
<link rel="stylesheet" type="text/css" href="http://greenbex.com/css/style.css"> //old css from another page
<link rel="stylesheet" type="text/css" href="css/font-awesome.css">
<script src="http://greenbex.com/js/onepagescroll.js"></script>
<title>ElectroFen - Team</title>
</head>


This way all works fine and does the work
but once I change it to my local new custom css
<link rel="stylesheet" type="text/css" href="css/style.css">
page goes blank and says


Uncaught TypeError: $(...).onepage_scroll is not a function(…)
I have no idea what causes the problem ...


my css file starts with this

/* Prefix */



#mainpage {
height: 100vh;
width: 100vw;
}
html {
display: none;
}

.col-md-8, .col-md-4 {
padding: 0;
margin: 0;
}
.row {
margin-right: 0;
margin-left: 0;
}
/* HOME PAGE */
....



EDIT


this is the full code, this way it works.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="http://greenbex.com/css/onepage-scroll.css">
<link rel="stylesheet" type="text/css" href="http://greenbex.com/css/style.css">
<link rel="stylesheet" type="text/css" href="css/font-awesome.css">
<script src="http://greenbex.com/js/onepagescroll.js"></script>
<title>ElectroFen - Team</title>
</head>
<body>
<div class="main">
<section id="header">
<!-- code -->
</section>
<section id="projects">
<!-- code -->
</section>
<section id="projects">
<!-- code -->
</section>
<section id="projects">
<!-- code -->
</section>
</div>
</body>
<script src="http://greenbex.com/js/jquery.js"></script>
<script src="http://greenbex.com/js/bootstrap.js"></script>
<script src="http://greenbex.com/js/script.js"></script>
</body>
</html>


Afetr adding my new custom css file
<link rel="stylesheet" type="text/css" href="css/style.css">
it doesn't work

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="http://greenbex.com/css/onepage-scroll.css">
<link rel="stylesheet" type="text/css" href="http://greenbex.com/css/style.css">
<link rel="stylesheet" type="text/css" href="css/font-awesome.css">
<link rel="stylesheet" type="text/css" href="css/style.css"> //this line
<script src="http://greenbex.com/js/onepagescroll.js"></script>
<title>ElectroFen - Team</title>
</head>
<body>
<div class="main">
<section id="header">
<!-- code -->
</section>
<section id="projects">
<!-- code -->
</section>
<section id="projects">
<!-- code -->
</section>
<section id="projects">
<!-- code -->
</section>
</div>
</body>
<script src="http://greenbex.com/js/jquery.js"></script>
<script src="http://greenbex.com/js/bootstrap.js"></script>
<script src="http://greenbex.com/js/script.js"></script>
</body>
</html>


and says


script.js:19 Uncaught TypeError: $(...).onepage_scroll is not a function(…)


script.js has

//custom script here
onePageScroll(".main", {
sectionContainer: "section", // sectionContainer accepts any kind of selector in case you don't want to use section
easing: "ease", // Easing options accepts the CSS3 easing animation such "ease", "linear", "ease-in",
// "ease-out", "ease-in-out", or even cubic bezier value such as "cubic-bezier(0.175, 0.885, 0.420, 1.310)"
animationTime: 1000, // AnimationTime let you define how long each section takes to animate
pagination: true, // You can either show or hide the pagination. Toggle true for show, false for hide.
updateURL: false, // Toggle this true if you want the URL to be updated automatically when the user scroll to each page.
beforeMove: function(index) {}, // This option accepts a callback function. The function will be called before the page moves.
afterMove: function(index) {}, // This option accepts a callback function. The function will be called after the page moves.
loop: true, // You can have the page loop back to the top/bottom when the user navigates at up/down on the first/last page.
keyboard: true, // You can activate the keyboard controls
responsiveFallback: false // You can fallback to normal page scroll by defining the width of the browser in which
// you want the responsive fallback to be triggered. For example, set this to 600 and whenever
// the browser's width is less than 600, the fallback will kick in.
});
$(document).ready(function(){
$(".main").onepage_scroll();
});

Answer

Since you are using the pure version of the plugin, remove the line $(".main").onepage_scroll();

The plugin has already been loaded, and the re-initialization is not needed, which is also causing problems.

Comments