2015-12-10 22 views
1

我想在html Dom的所有圖像標記上添加圓形標記圖像(25 * 25像素)。 它的作品,但與我的代碼的位置有時會改變,它經常顯示在圖像下。Jquery在圖像問題下顯示圓形標記圖像

這裏是我的代碼:

jQuery("img").each(function() { 
    var image = jQuery(this); 
    if ((image.width() >= 512) && (image.width() <= 2048)){ 
     image.parent().css('display', 'inline-block'); 
     var top_pos = image.offset().top+200, left_pos = image.offset().left+150;      
     image.parent().append('<div class="tag_image first_tag_image1" id="first_draggable1" style="position:absolute;'+'top:'+top_pos+'px;'+'left:'+left_pos+'px;">'); 
     //do something 
    } 
}); 

如果誰知道該怎麼做? 如有任何問題,請添加評論。

+0

給我們https://jsfiddle.net/ – Sko

+0

你可以用css來實現這一點。例如,爲您的圖像添加一個':before'或':after'元素。 – Gonzalo

+1

@Gonzalo非常感謝。我解決了問題。 –

回答

2

您必須使用:before。 例如image.before('//一些代碼')

+1

我已經解決了這個問題。 –