Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #40 from magebarf/master

Add option for restoring the original positions upon disable.
  • Loading branch information...
commit bf789ceb03a9e016ae76402375be4b2518906277 2 parents d4f9b33 + c10a74d
@cameronmcefee authored
Showing with 18 additions and 4 deletions.
  1. +16 −4 js/plax.js
  2. +2 −0  readme.md
View
20 js/plax.js
@@ -75,8 +75,8 @@
// no can-doesville, babydoll, we need pixels or top/left as initial values (it mightbe possible to construct a temporary image from the background-image property and get the dimensions and run some numbers, but that'll almost definitely be slow)
return
}
- layer.startX = x[2] || 0
- layer.startY = y[2] || 0
+ layer.originX = layer.startX = x[2] || 0
+ layer.originY = layer.startY = y[2] || 0
} else {
// Figure out where the element is positioned, then reposition it from the top/left
@@ -87,8 +87,8 @@
'right' :'',
'bottom':''
})
- layer.startX = this.offsetLeft
- layer.startY = this.offsetTop
+ layer.originX = layer.startX = this.offsetLeft
+ layer.originY = layer.startY = this.offsetTop
}
layer.startX -= layer.inversionFactor * Math.floor(layer.xRange/2)
@@ -237,6 +237,18 @@
disable: function(opts){
$(document).unbind('mousemove.plax')
window.ondeviceorientation = undefined
+ if (opts && typeof opts.restorePositions === 'boolean' && opts.restorePositions) {
+ for(var i = layers.length; i--;) {
+ layer = layers[i]
+ if(layers[i].background) {
+ layer.obj.css('background-position', layer.originX+'px '+layer.originY+'px')
+ } else {
+ layer.obj
+ .css('left', layer.originX)
+ .css('top', layer.originY)
+ }
+ }
+ }
if (opts && typeof opts.clearLayers === 'boolean' && opts.clearLayers) layers = []
}
}
View
2  readme.md
@@ -94,6 +94,8 @@ Disable parallaxing.
__Parameters__
+`restorePositions` — Boolean: (optional) resets all previously defined layers to their original positions when plax is deactivated.
+
`clearLayers` — Boolean: (optional) clears all previously defined layers when disabling.
Please sign in to comment.
Something went wrong with that request. Please try again.