Home › Forums › JavaScript › Can I put a timeout function inside a for loop?
- This topic is empty.
-
AuthorPosts
-
July 18, 2014 at 6:19 pm #175773
nixnerd
ParticipantI would really like to achieve this but I can’t figure out how to do it.
Any general pointers?
I won’t post a codepen… but this is way to dependent on local files.
July 18, 2014 at 7:20 pm #175776Alen
ParticipantWhat are you trying to solve?
I’m thinking it would be easier to build up some sort of array, then have a function set to run on a interval, pulling values out and doing whatever needs to be done.
You can’t pause execution, it would render the whole page inaccessible as JavaScript is render blocking.
July 18, 2014 at 7:43 pm #175777nixnerd
ParticipantDude, the whole thing is a hack because there’s no other way. It only works with local files… so let me see if I can upload it all to my server and then post some code. Codepen just won’t work.
My apologies. I know this isn’t how it’s done.
July 19, 2014 at 3:00 pm #175836nixnerd
ParticipantAlright… So, here is the item I’m working on:
http://joektempleton.com/sandbox/sps0/
As you can see, when you scroll through the photos, the background photo is the same as the foreground, but the background photo is full screen and blurred. It also moves at the same speed, but it’s much bigger… so it creates sort of a lateral parallax effect.
One cool thing about this slider is that you just load it up with images inside the
.strip
class and it then pulls those photos withdata-path
and makes them background images of the.backslide
classes.I’m using a tool called blur.js to blur the background photos.
HERE IS THE PROBLEM… Well, two really:
- Right now, I’m having to manually set all the
.backslide
classes to be blurred. I need this done automatically… but I can’t figure out how. I tried to create a function that does it for me inside a loop… but that doesn’t work. - Blur.js was built to really only blur one element on a given page. So, you can blur one element, then you need to use timeout functions to blur the rest. I’m ABSOLUTELY certain there is another way… I just need to find it. I tried blurring new elements on click, but that was too slow and choppy.
Here is the gist that controls which elements get blurred:
https://gist.github.com/joetemp/d19f02156885f36528c6
Here is the gist of the JS that controls the slider actions:
July 19, 2014 at 5:05 pm #175846nixnerd
ParticipantKeep in mind, this is under development and far from a finished slider. Also, if you have suggestions on better way to blur photos, I’m open!
July 19, 2014 at 6:35 pm #175850__
ParticipantJust to clarify: the timeout is necessary? if so, is there a minimum interval that seems to be effective?
Have you already tried something like
$( /* your selector */ ).each( function( i,e ){ $( e ).blurjs(); } );
I know a codepen would be difficult, but it would also be very helpful. Perhaps using placekitten or something…?
July 19, 2014 at 7:30 pm #175854nixnerd
ParticipantJust to clarify: the timeout is necessary?
It’s the only way I’ve found, other than a click event that works. Again, click event was waaaay too slow. There might be a way with a callback to fire them automagically when one finishes. I’d WAY prefer that to this stupid timeout BS. Also, in terms of an interval, I played around with it quite a bit. 100 is too small. 500 works. I guess I could try 250.
Have you already tried something like …(some code)
I didn’t even try
each
because I figured if you can’t build a function inside afor
loop, you won’t be able to do it insideeach
. I’ll give it a shot though. On that note, apparently you can build a function inside a loop but you have to return the function somehow. I tried it like 10 times and never got it to work.I know a codepen would be difficult, but it would also be very helpful. Perhaps using placekitten or something…?
I haven’t inspected blur.js too much… but every time I try to use a remotely hosted photo… it throws me an alert and doesn’t work. Believe me, I hate this nonsense too.
What I really think I need is what is called a “function factory” or a constructor object.
July 19, 2014 at 7:44 pm #175861nixnerd
ParticipantI’ve never had super good luck with SVG filters. I suppose I could try. Do they work on straight up photographs?
July 19, 2014 at 7:46 pm #175862nixnerd
ParticipantDamn… that would be a simple and elegant solution. I’m going to give it a shot.
July 19, 2014 at 7:48 pm #175863JacobPeters
ParticipantReally? I have to use them quite a few times for friends tumblr blogs. They wanted all their posts to be black and white. Worked great. Plus, there is
filter: blur()
support on chrome;July 19, 2014 at 7:54 pm #175864nixnerd
ParticipantOk, so I found this:
http://ie.microsoft.com/testdrive/graphics/hands-on-css3/hands-on_svg-filter-effects.htm
But it doesn’t give me any indication on how this works with a photo. What does the construction look like?
July 19, 2014 at 7:58 pm #175866JacobPeters
ParticipantAlso, can I recommend using translates rather than margins? It would save time on repaints, and you’re already using scale.
July 19, 2014 at 8:02 pm #175868nixnerd
ParticipantYeah, I meant to change that. My bad.
I must be using svg filters wrong. Whenever I try to apply one to an image… the image disappears.
July 19, 2014 at 8:09 pm #175870JacobPeters
ParticipantDoes this work?
July 19, 2014 at 8:12 pm #175871nixnerd
ParticipantCertainly does!!! I just figured that out like right before you posted that but thanks!
Now the question is… does it work with a background image? I’m working on that now.
- Right now, I’m having to manually set all the
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.