November 20, 201114 yr I'm designing a site where rarely in the background I want little images with jQuery effects going on. Currently I have about 6 of them. Obviously I don't want them all happening at the same time, even though they are subtle.. 6 really isn't. I also don't want them happening on every page. I'd like a randomly chosen one of these elements to be displayed let's say one out of every hundred page views. They are to be 'treats'. As an example, it's a starry night themed design so maybe one in every 1000 page views gets to see one of the 6 effects. I figure PHP would be best for this . Could likely do it in jQuery by hiding the others but that doesn't seem efficient. I'm a PHP dunce but I cobbled this together so far. It works but it always shows one of the choices and the only solution I can think of is to add another 700 cases that are blank. Which I'm pretty sure is moronic. Also fairly sure it's still loading in every element so I'd love a way to stop that. So I would I take this and A) Make the choosing of one of these cases a rare event and Possibly stop it loading in the events it didn't choose? Any help appreciated! <? $num = Rand (1,6); switch ($num) { case 1: ?> <div id="balloon"></div> <?php break; case 2: ?> <div id="rocket"> <div id="ship"></div> <div id="blast"></div> </div> <?php break; case 3: ?> <div id="star"></div> <?php break; case 4: ?> <div id="batsignal"></div> <?php break; case 5: ?> <div id="UFO"></div> <?php break; case 6: ?> <div id="planet"></div> <?php } ?> (Re-reading the very idea of this sounds cheesy but it's really not that bad lol)
November 21, 201114 yr Just include all that code in another rand() of 1 in 1000 or whatever: <?php $prob = rand(1,1000); if($prob == 1000){ $num = Rand (1,6); switch ($num) { case 1: ?> <div id="balloon"></div> <?php break; case 2: ?> <div id="rocket"> <div id="ship"></div> <div id="blast"></div> </div> <?php break; case 3: ?> <div id="star"></div> <?php break; case 4: ?> <div id="batsignal"></div> <?php break; case 5: ?> <div id="UFO"></div> <?php break; case 6: ?> <div id="planet"></div> <?php } } ?>
November 21, 201114 yr I think it's a nice touch, occasionaly one comes across a site that does someting similiar but (local)time based with different headers or background images depending upon wether it is day or night where the visitor comes from.
November 21, 201114 yr Author Just include all that code in another rand() of 1 in 1000 or whatever: Champion! +1
November 24, 201114 yr The problem with the additional 1 in 1000 if loop is that you may never actually load anything ever...Your special event could become extremely rare indeed. In my opinion you are better off displaying them at certain times of the day, then you guarantee that they will actually be shown at some point, to somebody.
November 24, 201114 yr The problem with the additional 1 in 1000 if loop is that you may never actually load anything ever...Your special event could become extremely rare indeed. In my opinion you are better off displaying them at certain times of the day, then you guarantee that they will actually be shown at some point, to somebody. dddougal is right, if in a couple hours when I get home a solution hasn't been found, I'll have a look for you, I have a slight idea...
November 24, 201114 yr I think 1 in 1000 chance of any animation being shown is a little crazy - you'll never see them. Try a 1 in 10 chance, or a 1 in 20 maybe. But 1 in 1000 would mean they would never ever be seen. Good luck
Create an account or sign in to comment