Comments (12)
How should this manifest itself? What should actually happen when you "destroy" your Superscrollorama instance?
One (simple?) way of doing it could be to add a namespace to the scroll bind that keeps superscrollorama up to date and then let the moving items stay in place where they where when the instance got killed.
Another way is to restore all back to their "default css"-state. I don't know for sure how one would do that.
A third way is to complete all animations. To set the progress of all of them to 1.
A fourth way is the same as the above, but to set them all to progress 0.
All of them requires some rewriting of the pin function.
from superscrollorama.
I think the easier way is your first solution.
In fact my main problem is when we resize the window.
For exemple, I have the following line :
scrollorama.addTween(200, TweenMax.to(
If the user resize the window, my "$(window).width()" is now wrong, so I would like to implement in the "onResize" handler something to destroy the superscrollorama and then recreate it with the new proper values.
The easier way should be to be able to "update" some scrollorama tweens, but I dont' think it's possible (maybe I'm wrong ?)
from superscrollorama.
I have been meaning to look into exposing the internal arrays of tweens for quite some time now, but work is keeping me busy.
The basics of my plan was to simply see what happens if you expose the internal animObjects
and pinnedObjects
arrays as part of the superscrollorama instance. The problem I expect is that of making sure the "updated" tweens, that may now replace their old counterparts, "understand" in what state they should be initiated as, but I might be over cautious.
Another solution might be to try to convince the greensock-guys to add the capability of using functions as css attribute definers. This might already work, but i can not find it documented.
from superscrollorama.
I did some digging and this can be done using existing features in Greensock TweenMax.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
body {
height: 2500px;
position: relative;
margin: 0;
}
#mover {
position: absolute;
background: orange;
padding: 5px;
font-size: 10px;
top: 0;
left: 0;
}
</style>
</head>
<body>
<div id="mover">I am<br/>Mover.</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="https://raw.github.com/johnpolacek/superscrollorama/master/js/greensock/TweenMax.min.js"></script>
<script src="https://raw.github.com/johnpolacek/superscrollorama/master/js/jquery.superscrollorama.js"></script>
<script>
(function(){
var sc = new $.superscrollorama();
var tween = new TweenMax($('#mover'), 0.5, {
css: {
left: $(window).width() - 240,
top: 600
}
});
sc.addTween(0, tween, 400)
$(window).on('resize', function(){
tween.updateTo({
css: {
left: Math.round($(window).width() - 240) * 1,
top: 600
}
})
});
}())
</script>
</body>
</html>
The issue of being able to destroy a superscrollorama instance is not yet discussed or completed, but the actual issue discussed in this thread should be resolved.
from superscrollorama.
Hello, I am having trouble as well figuring out how I would handle screen resizes.
I have tried your code and it does not seem to work.
edit:
Got it kind of working by adding invalidating the tween first. I added tween.invalidate();
before the updateTo tween. This only works if you resize the window when the tween hasn't started yet, otherwise you get strange positioning.
Is there anyway to get this to work on a whole set of tweens in a timeline?
from superscrollorama.
I think this has more of a need in long running Sites, where the dom isn't being refreshed.
We are currently using turbolinks, and we have no clean way to shut down superscrollorama, and unbind the tracking events, when we switch out our dom body
from superscrollorama.
A removeTween, removePin method will be added in future updates.
Destroying the Superscrollorama instance itself should not be necessary.
from superscrollorama.
I just added removeTween and removePin. See documentation for details. :)
Hope this helps.
regards,
Jan
from superscrollorama.
I actually have Superscrollorama firing twice when animating in and out of a page. It would be useful if we could delete the entire timeline with a "destroy" method.
from superscrollorama.
This probably isn't the best way to go about it but it works.
superscrollorama.destroy = function () { $(window).off('scroll'); delete superscrollorama; };
from superscrollorama.
@k33n I tried your method and was still seeing it fire. I was thinking wiping out the pinned and animated elements from the array would work, but still no dice.
superscrollorama.destroy = function () {
animObjects = [];
pinnedObjects = [];
};
from superscrollorama.
This is what @rposborne did originally. In our case we needed to destroy when Turbolinks fetched new pages.
The change to superscrollorama:
superscrollorama.destroy = function () { animObjects = [] // Unbind the window scroll event $(window).off('scroll'); delete superscrollorama; };
Then
$(document).on("page:fetch", function() { window.tweenController.destroy(); });
from superscrollorama.
Related Issues (20)
- Trouble with Mobile Superscrollerama HOT 2
- How to disable Superscrollorama in mobile devices? HOT 1
- Mac chrome lag HOT 2
- Make a tween.js version? HOT 1
- CSS problem HOT 4
- Scroll not working on PC mouse wheel HOT 1
- Superscrollorama and screen size/media queries HOT 1
- Superscrollorama autostart from top HOT 1
- Superscrollarama does not reverse start values HOT 4
- How do I scroll two time for pinned element before the window go to next pinned element HOT 1
- Adding delay to tween HOT 4
- Query: flashing mid animation HOT 1
- Skip pinned element HOT 4
- Is there a seek functionality ? HOT 1
- Uncaught TypeError: $.superscrollorama is not a function HOT 2
- Scrolling performance improvements via layerization HOT 4
- add package.json HOT 3
- Espaçamento no topo
- help scroll
- My SuperScroll Orama not working in firefox while working in chrome
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from superscrollorama.