Search code examples
jqueryhtmlrandomposition

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>

Solution

  • 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