Last active
December 15, 2015 04:59
-
-
Save mbseid/5205646 to your computer and use it in GitHub Desktop.
Require.js intro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node r.js -o build.js | |
node r.js -o build.js optimize=none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Require.JS - Quicktro</title> | |
<script data-main="js/main" src="js/lib/require.js"></script> | |
</head> | |
<body> | |
.... | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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