www.webdeveloper.com
Results 1 to 2 of 2

Thread: random size with 2 fixed values

  1. #1
    Join Date
    Feb 2011
    Posts
    47

    random size with 2 fixed values

    Hi,
    im using the code below to load instagram images then I'm giving them a random width.
    Id like to alter the random with function so that there's only 2 different values to randomize. E.g all images ('maxWidth') will either become 200px or 300px.



    HTML Code:
    	$.ajax({
            type: "GET",
            dataType: "jsonp",
            cache: false,
            url: "https://api.instagram.com/v1/users/178173879/media/recent/?access_token=178173879.e651f2a.16d3f37736f24149b6cca8b03e2ace79",
            success: function(data) {
            
    	for (var i = 0; i < 10; i++) {
    			maxWidth = Math.floor(115 + (Math.random() * 135));
    	$("#container_content").append("<div class='instagram item'> <a target='_blank' href='" + data.data[i].link +
    "'><img src='" + data.data[i].images.low_resolution.url +"' width='" + maxWidth + "' /></img></a></div>");
    			}			
    		}
        });

  2. #2
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,674
    Code:
    	for (var max,ary=[200,300],i = 0; i < 10; i++) {
         max=ary[Math.floor(Math.random()*ary.length)];
         alert(max);
        }
    Vic

    God loves you and will never love you less.

    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles