-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Question about window resizing issue. #401
Comments
I'm not prinzhorn, but I had the same issue; I ended up rewriting the attributes dynamically (using jquery) before calling refresh(). That worked fine. I had to 'chain' the refresh call after rewriting the attributes, as in setTimeout(function() { skrollr.get().refresh()},0) probably to give the browser time to apply the DOM changes. $2c, |
That is what I was thinking about doing as well. I already have the code to remove all the current attributes but had hoped there would be an easier way hah. |
pike67, how were you able to get it to work? For some reason, mine only seems to work the first time you resize. If you resize again it breaks. I have my code setup to remove all the data tags, then check to see if you're done resizing. When that check passes, it reloads all my functions that I need to change content heights and add my data tags for skrollr but I still end up with extra data tags and the wrong skrollr amounts. |
My question about this was here .. #387 Let me see if I can paste code here: Suppose you want to change the attributes on an element called $elm:
And then, when all is done,
This worked throughout ie7 to ipad. There may be typoos in the above code .. it was abstracted from my thing. |
I used an each function instead of a for loop. Like this:
Maybe I'll try the for loop though. Mine doesn't seem to be working exactly the way I want it to. Sometimes it only removes one of the data attributes instead of both. |
That would also remove any other data- attributes, but if you dont care, thats ok. Mine checks for data-xxx where xxx is numeric. |
Ya, I don't have any other data attributes so I built mine as kind of a "remove all" function. Either way, I still can't get it to work the way I need it to. When the window resizes, my function that adds the data attributes seems to add them before my function can remove them all so I end up with way too many and my skrollr gets messed up. |
Now I'm just really confused. I have been able to get it to work sometimes the first time the browser is resized, but it never works any time after that. |
Try this: Listen to the resize event yourself and call window.addEventListener('resize', _.debounce(function() {
//Update data attributes here.
skrollr.get().refresh();
}, 300), true); Debouncing is needed because some OSs (e.g. Windows) fire resize events constantly while resizing, but you don't want to re-parse all elements all the time. |
The issue isn't updating all my variables, the issue is that I can't seem to update the data attributes that skrollr is using. Most of my vars I want to update constantly while resizing because I'm changing a bunch of images and content blocks depending on the height of the window. This code works fine, however, once all my heights change, the starting and stopping points of my animations, as well as how much they animate, also needs to change. I can't just add new data attributes, and I can't seem to remove them before I add them again and get skrollr to update. After a bunch of testing, I'm noticing that, even though I'm adding the data attributes with jqeury on load, when I remove them and re-add them, my script to detect them is no longer seeing them. |
Could you share your script? Do you by any chance use Edit: Well, seems like you do. Read the docs about it again http://api.jquery.com/data/
You need to use |
Oops, yes, forgot to mention. it seems <a data-123="foobar"> did not always return as $a.data('123') in jquery. Which I figured was a jQuery issue (after all, '123' is a weird variable name, too). So I loop the attributes in my loop above, not the .data() object. |
Ya, I use
and my code to remove them is what I showed you earlier:
|
Which is using |
I figured out the problem, or at least the solution. I need to add both the |
Hi guys, Could you post the solution snippet? #sborrowman |
I ended up adding both
Then, call my function that adds them again. Basically, I had to add and remove both attr and data every time the window resizes. I hope this helps. |
Thanks a lot mate, that was helpful. |
$(function() { Putting that after init did it for me. |
I'm using this plugin for a couple pages that I'm working on but have ran into a slight issue that I am hoping you could help me out with.
I have the animation working exactly the way I want, however, when I resize the browser a lot of the content sizes change as well. This means that all my starting and stopping points, and my transform amount all have to be different.
I see you have a refresh call, which looks like it calls the init again, but is there a way to update the data amounts before you refresh?
Thanks in advance.
The text was updated successfully, but these errors were encountered: