Hello,

i've created a function to generate user defined number of an image.
I'm sure that it's not the optimal solution, because over 100 elements
most browsers renders it very slow...

Here is the sample page: http://resolution.capsule.hu/ (the × image is
randomly generated)

The js function:

function exRandomizer(param,maxDim,transp) {
        var x = $('body').width() - maxDim;
        var y = $('body').height() - maxDim;

        for ( var i = 0; i < param; i++ ) {
                var dim = Math.round(Math.random() * maxDim);

                $('#container').before('<img src="static/images/ex.gif" alt=""
class="eX" id="eX_' + i + '" />');

                $('#eX_' + i)
                        .css({
                                opacity: transp,
                                zIndex: 1,
                                top: Math.round(Math.random() * y) + 'px',
                                left: Math.round(Math.random() * x) + 'px',
                                width: dim + 'px',
                                height: dim + 'px'
                        });
        }
        return false;
}

and you can call it for example: exRandomizer(100,250,0.1);

I would be very happy, if someone could post a more optimal version -
it's very useful, and I think many of beginner jquery users could
learn a lot form an example.

Thanks in forth!

{ csongor }

Reply via email to