当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - tumblr - How can I make a div appear based on the height of a certain post's caption?

问题描述:

I am editing my theme on tumblr and trying to use jquery to make it so that a certain div only appears if the height of a text post or a post's caption is over 250px. It is pretty simple and seems to be working, but only seems to take in the first post and then sets the div visible for all the other entries too. Does anyone know how I can adjust the code so that each post goes through the code instead of it being set for the first post only?

note: #entry is the ID that's being used for styling the posts. .caption is the caption's class and .b is the div I want shown only if the caption is over a certain height.

$(document).ready(function(){

if ($("#entry .caption").height()>250) {

$("#entry .b").show();

}

});

Please let me know if you can help. Thanks!

网友答案:

Try change the

if ($("#entry .caption").height()>250)

to:

if ($("#entry .caption").height()>=250) 

so you also match 250px of height and above.

And for each element that matches:

$(document).ready(function(){
    $('.entry .caption').each(function(i, ui){
        if ($(this).height()>=250) {
            $(this).parents('.entry').find('.b').show();
        }
    });
});
分享给朋友:
您可能感兴趣的文章:
随机阅读: