Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the order of pictures at midnight

I have a set of picture ads that I want to change the order of every day at midnight.

Basically so that one day it will be like this

<img src="image1">
<img src="image2">
<img src="image3">
<img src="image4">

and the next day it will look like this

<img src="image4">
<img src="image1">
<img src="image2">
<img src="image3">

How could I accomplish this with javascript, jquery or php. Not concerned about what language I use, just need to figure it out. Thanks..

like image 395
Zach Avatar asked Feb 08 '12 02:02

Zach


People also ask

Can you change the order of pictures after you post them?

You can change the order of photos in a photo dump to create an entirely new look. Instagram unveiled the option to edit a carousel of multiple images back in November 2021. Not only can you delete photos from a photo dump, but you can also rearrange your photo album by deleting and re-adding images to it.

How do I change the order of pictures in gallery?

To perform other actions, click the three-dot icon in the upper right and select Edit Album. You can now rearrange photos by dragging and dropping them to new positions, remove a photo by clicking its X mark, and change the name of the album.


1 Answers

Try this one http://jsfiddle.net/KQwf2/1/

HTML:

<img src="http://solarpanels2green.com/images/one.gif" title='1'>
<img src="http://solarpanels2green.com/images/two.gif" title='2'>
<img src="http://solarpanels2green.com/images/three.gif" title='3'>
<img src="http://solarpanels2green.com/images/four.gif" title='4'>

and js code

var all = $('img'), 
        shift = Math.floor(
          (new Date().getTime() - new Date().getTimezoneOffset() * 60000)
         / (24 * 3600 * 1000)) % all.length;

all.filter(':gt(' + (all.length - shift - 1) + ')')
   .insertBefore(all.first());

It calculates the MOD of the division of number of days passed since the midnight of January 1, 1970 by the number of the elements in the images list, takes this amount of images from the bottom of the list and moves them in front of the list.

Updated to take into account the timezone of the visitor.

like image 51
Cheery Avatar answered Sep 26 '22 17:09

Cheery