Monday, July 08, 2013
This methode is so rarely needed by bloggers, cause in general, most of contents are better to show just like that on website. If there are sorts of contents that are good, better to show as random, those would be text quotes, like-featured-content "images", or somekind. From millions, maybe billions of bloggers out there, there must be some of those are presenting, or just willing to present such contents on their website. So, here i am now, explain about how to create random text quotes or images, showing those the way to make real their imagination.

Might you've known that many bloggers out there are talking about this methode, give a lot options of style of the form, but very few of those are giving the simple methode like what i'm going to give to you.

If you prefer the simple style instead of those that are made "colorfull", like me, then this is just what you want. Code length no longer than 200, can be placed everywhere, and even you can still add your own code if you'd like.

Of course colorfull is good, but when colorfull takes code too much and thus add some additional loads to your blog, ask your self, should you make something like this colorfull?

Even sometimes colorfull is not good by the way.

Well, then, let's show you the code. Here you can define whether or not you want to use an image for the background, you can set as many contents as you want to include, and after all, you can add your own code to style its appearance if you'd like. And that, it's javascript code, there is no way you can create random contents with CSS.

<script type='text/javascript'>
var myTextQ=new Array();
var myTextQ[0]="Your Quote 1";
var myTextQ[1]="Your Quote 2";
var myTextQ[2]="Your Quote 3";
var random=Math.floor(3*Math.random());
document.write("<div style='background:#ffffff url(background image url) no-repeat;margin:1px;'>");
document.write("<b>");
document.write("Quote:");
document.write("</b>");
document.write(myTextQ[random]);
document.write("</div>");
</script>

Now listen to me.. If you could need this, you could be a newbie. Well, these are rules that you need to know. :)

1. To write text in javascript, you need to add backslash ("\") next to special characters like "'", ";", or somekind. Not realy many characters, just a few.

Pay attention on the following example:

<script>
myTextQ[0]="Do you like my blog? You\'ll be welcomed to follow up on facebook.";
</script>

2. var random=Math.floor(3*Math.random()), you need to set the number ("3") accordingly with the "quotes" (say it so) that you include into the script. Say your total quotes is 5, then you have to change the number to 5 too.
3. The number must start from 0 ("[0], [1], [2], [3]").
4. If you don't want to use an image for the background, remove the order " url(background image url) no-repeat".
5. If you use an image for the background and you want to repeat the image to show, change "no-repeat" with "repeat".

Here are some options for repeating image

- repeat: repeat as needed.
- repeat-x: repeat horizontal.
- repeat-y: repeat vertical.
- repeat top left: image placed and repeat from top left.
- repeat top right: image placed and repeat from top right.

That's it everybody. If you have any question about this, let me know that, maybe i can help you.

0 comments:

Post a Comment