开发者

Jquery append - Image inline

开发者 https://www.devze.com 2023-03-22 12:17 出处:网络
I\'m trying to add images to a div. When the images append. The are displaying \"block\". I need them to display inline.

I'm trying to add images to a div. When the images append. The are displaying "block". I need them to display inline.

This is the code I am running:

$(".showvideothumbs").append($('<img src="/garageimages开发者_运维问答/'+data.thumb+'" style="display:inline">').hide().fadeIn(2000));

I've tried wrapping it in a div that has "display:inline" set, but jquery changes that to "display:block".


Use callback.

$(".showvideothumbs").append('&lt;img src="/garageimages/'+data.thumb+'" style="display:none;"/&gt;').find('img').fadeIn(2000,function(){
    $(this).css('display', 'inline');
});


Instead of inline style try

.css('display', 'inline')


I'm a little confused as to why you are doing this:

$('<img src="/garageimages/'+data.thumb+'" style="display:inline">').hide().fadeIn(2000)

You are, in effect, creating an image and then hiding and showing it before it is even added to the DOM.

Does setting the style using .css('display', 'inline') work more effectively for you?

$(".showvideothumbs").append($('<img src="/garageimages/'+data.thumb+'" style="display:inline">').css('display', 'inline'));

You can then apply the hide/fade to the containing DIV (formatted for greater ease of reading):

$(".showvideothumbs")
    .append($('<img src="/garageimages/'+data.thumb+'" style="display:inline">')
         .css('display', 'inline'))
    .hide().fadeIn(2000);
0

精彩评论

暂无评论...
验证码 换一张
取 消