Skip to content

Instantly share code, notes, and snippets.

@mbseid
Last active December 15, 2015 04:59
Show Gist options
  • Save mbseid/5205646 to your computer and use it in GitHub Desktop.
Save mbseid/5205646 to your computer and use it in GitHub Desktop.
Require.js intro
node r.js -o build.js
node r.js -o build.js optimize=none
define({
app_name: "scroller",
baseUrl: "js/",
shim : {
'jquery' : {
exports: '$'
},
'jquery-scroll' :{
deps:['jquery'],
exports: 'scrollTo'
}
},
paths : {
'jquery': 'lib/jquery-min',
'jquery-scroll': 'lib/jquery.scrollTo'
}
});
define(["jquery"], function($){
var SlideScroll = function(){
var slide = 0;
var length = null;
var nodes = null;
var start = function( nodesName ){
nodes = $(nodesName);
length = nodes.length;
$(window).keypress( keypress )
}
var keypress = function( e ){
..
}
var moveForward = function(){
slide++;
goTo(slide);
}
var moveBackward = function(){
slide--;
goTo(slide)
}
var goTo = function(number){
$(window).scrollTo(nodes[number]);
}
return {
start: start
}
}
return new SlideScroll();
});
<html>
<head>
<title>Require.JS - Quicktro</title>
<script data-main="js/main" src="js/lib/require.js"></script>
</head>
<body>
....
</body>
</html>
(function(root){
require(["js/config.js"], function(config){
requirejs.config(config);
require(["slideScroll"], function(slideScroll){
slideScroll.start('section');
});
});
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment