css - How do I add a comment to an image using jQuery -


so trying replicate facebook's picture tagging functionality, , have functionality onclick, box created , there comment box.

now issue want able (without doing back-end processing) take input input field , add in form underlying image area have selected. add small image area, shows comment there.

how do that?

see code below have comment box:

<script type="text/javascript">      $(function() {             var tag_box = $("<div>").appendto("body").css({                 "width": "40px",                 "height":"40px",                 "border":"4px solid #000000",                 "position":"absolute",                 "display":"none",                  "padding":"15px"                 });          var comment_box = $("<form action='#'><input id='comment' type='text' name='comment' placeholder='add comment'></form>").appendto(tag_box).css({"position":"absolute"});                      $("#image-wrapper").live('click', function(e){             tag_box.css({                 "left": e.pagex - 40,                 "top": e.pagey - 40,                  "display": "block"                 })             .after(comment_box.css({                 "left": e.pagex - 65,                 "top": e.pagey + 40             }));              });          });   </script> <body>     <div align="center">        <img src="images/test.gif" width="760" height="182" alt="test" id="image-wrapper">      </div> </body> 

now...whenever user presses enter, info in comment box appended url so:

.html?comment=comment value#

thanks

edit: bad...i left out html...i have appended script tag above.

this may not best solution, give try :)

<script type="text/javascript">     $(function() {          var tag_box = $("<div class=\"comment-box\"></div>").css({                 "width": "40px",                 "height":"40px",                 "border":"4px solid #000000",                 "position":"absolute",                 "padding":"15px"         });          var comment_box = $("<form action='#'><input id='comment' type='text' name='comment' placeholder='add comment'></form>").appendto(tag_box).css({"position":"absolute"});                      $("#image-wrapper").live('click', function(e){             if($(this).parent().find('.comment-box').length === 0) {                 $(this).parent().append(tag_box).css('top',182).find('input#comment').focus();             }             return false;         });         $(".comment-box").             live('mouseenter mouseleave', function(event) {                 if(event.type == 'mouseout') {                     $(this).remove();                 }             })             .find('form').live('submit',function() {                 var comment = $(this).find('input#comment').val();                 var wrapperoffset = $("#image-wrapper").offset();                 var commentblock = '<div class="comment-block" style="position:absolute;color:white; display:block; float:left; clear:both; height:auto; width:760px; background:red;">' + comment + '</div>';                 var postop = wrapperoffset.top;                 $(commentblock).css({                     'width' : 760,                     'top' : postop,                     'left' : wrapperoffset.left,                     'z-index' : 100                 });                  if($("#image-wrapper").parent().find('.comment-block').length > 0) {                     var lastblock = $("#image-wrapper").parent().find('.comment-block:last');                     var lastblockoffset = $(lastblock).offset();                     $(commentblock).insertafter($(lastblock)).css('top', lastblockoffset.top + $(lastblock).height() + 4);                 } else {                     $(commentblock).insertbefore('#image-wrapper');                 }                  $(this).parent().parent().find('.comment-box').remove();                 $(this).get(0).reset();                 return false;             });     }); </script> <style> #image_container { display:block; height:auto; width:760px;margin:0 auto; background:yellow;} </style> <body> <div align="center">     <div id="image_container">         <img src="/images/image1.jpg" width="760" height="182" alt="test" id="image-wrapper">     </div> </div> </body> 

update :

<style> #image_container { display:block; height:auto; width:760px;margin:0 auto; background:yellow;} </style> <body> <div align="center">     <div id="image_container">         <img src="/images/image1.jpg" width="760" height="182" alt="test" id="image-wrapper">     </div> </div> 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -