afro360
afro360

Reputation: 620

Insert img where clicked

How can I insert a img wherever I click on the page?

I have the following code:

$(document).click(function(e){
    var x = e.pageX;
    var y = e.pageY;
    var string = x +','+ y;
    //alert(string);
    $('.marker').css(
        {
            'left': x +'px',
            'top': y +'px'
        },{
              duration:1000,
          })        
});

But this only moves the img around the page. I need to add multiple copies and POST to php url.

Thanks!

Upvotes: 2

Views: 93

Answers (2)

The Alpha
The Alpha

Reputation: 146201

You mean this ?

$(document).click(function(e){
    var x = e.pageX;
    var y = e.pageY;
    var string = x +','+ y;
    //alert(string);
    $('.marker:first').clone().css({
        'left': x +'px',                                        
        'top': y +'px',
        'position':'absolute'
    }).appendTo('body')      
});

DEMO.

Upvotes: 2

Ram
Ram

Reputation: 144689

clone the element.

$(document).click(function(e) {
    var x = e.pageX;
    var y = e.pageY;
    var string = x + ',' + y;
    //alert(string);
    $('.marker:first').clone().css({
        'left': x + 'px',
        'top': y + 'px'
    }).appendTo('body')
})

http://jsfiddle.net/xarGV/

Upvotes: 3

Related Questions