简体   繁体   中英

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();
        }
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM