简体   繁体   English

如何在JavaScript中使用tumblr变量来定位元素?

[英]How to target elements using tumblr variables in JavaScript?

I am struggling to target specific posts in my javascript. 我正在努力针对我的javascript中的特定帖子。 Tumblr has own variables such as {PostID} but I can't use them in Javascript in my theme or at least I don't know how to do it. Tumblr有自己的变量,如{PostID},但我不能在我的主题中使用它们或至少我不知道如何做到这一点。

My example: 我的例子:

I want to check if in a post a div's content is overflown. 我想检查一下div的内容是否溢出。 If that's the case JS should adjust the CSS of just this one's post. 如果是这种情况,JS应该调整这个帖子的CSS。 And then JS should move to the next post and so on. 然后JS应该转到下一篇文章,依此类推。

If you want to filter through all posts, instead use .each() . 如果要过滤所有帖子,请使用.each() (This is jQuery, not JS, but you have tagged your post with the 'jquery' tag so I assume you are happy to use it). (这是jQuery,而不是JS,但是你用'jquery'标签标记了你的帖子,所以我假设你很乐意使用它)。

For example: 例如:

$('.post-selector').each(function() {
    // check for overflow
});

If you are using infinite scroll you will need to do the same thing in the callback. 如果你使用无限滚动,你需要在回调中做同样的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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