Lex Sha
Lex Sha

Reputation: 57

Jquery random positioning of elements

I am trying to make the text randomly positioned on the screen. How do I do that?

I am using Textillate

jsfiddle

<h1 class="tlt1">Go </h1>

Upvotes: 0

Views: 3811

Answers (2)

Pradeep Gill
Pradeep Gill

Reputation: 318

You can achieve this either by position:fixed OR position:absolute.

$('.tlt').each(function(){
        $(this).css({"left": Math.random() * window.outerWidth , "top": Math.random() * window.outerHeight}).textillate();
});

OR

$('h1').each(function(){
        $(this).css({"left": Math.random() * window.outerWidth , "top": Math.random() * window.outerHeight}).textillate();
});

Updated jsfiddle

Upvotes: 1

Keegan Teetaert
Keegan Teetaert

Reputation: 673

You should set your CSS for your h1 tags to position:fixed. Then in your javascript for each h1 your generate set its left property to Math.random() * window.outerWidth and its top property to Math.random() * window.outerHeight.

Upvotes: 0

Related Questions