Skip to content

Instantly share code, notes, and snippets.

@AppWerft
Last active August 29, 2015 14:19
Show Gist options
  • Save AppWerft/d87dbe550f559769b76e to your computer and use it in GitHub Desktop.
Save AppWerft/d87dbe550f559769b76e to your computer and use it in GitHub Desktop.
/*
creates a parallax widget, top is UIimage, bottom is UIview
parameters:
image : url || Ti.Blob
view : UIView
*/
module.exports = function() {
var args = arguments[0] || {};
var imageheight =0;
var self = Ti.UI.createScrollView({
scrollType : 'vertical',
top : 0
});
self.topimage = Ti.UI.createImageView({
image : args.image || 'http://lorempixel.com/1200/800/sports/Dummy-Text/',
top : 0,
height : imageheight,
width : Ti.UI.FILL,
height : Ti.UI.SIZE,
zIndex : 99
});
self.add(self.topimage);
self.add(args.view);
self.children[1].opacity=0;
self.topimage.addEventListener('load', onloadFunc);
function onloadFunc() {
imageheight = self.topimage.size.height;
self.children[1].top = imageheight + 15;
self.removeEventListener('load', onloadFunc);
self.children[1].animate({
opacity : 1
});
}
self.addEventListener('scroll', function(_e) {
self.topimage.top = _e.source.contentOffset.y * 0.1;
});
Ti.Gesture.addEventListener('orientationchange', onloadFunc);
return self;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment