简体   繁体   English

无限滚动的tumblr自定义照片集大小

[英]tumblr custom photoset size with infinite scroll

I've been struggling a bit with javascript lately and to be honest: I have not really a clue about it. 我最近一直在用javascript挣扎,老实说:我对此并不了解。

The posts on my tumblr have a width of 350px, but because the photosets are using iframes, I was looking for a different solution on photosets and found this code: 我的tumblr上的帖子宽度为350px,但是由于照片集使用的是iframe,因此我在照片集上寻找其他解决方案,并找到了以下代码:

<script type="text/javascript">
//This will change the source address and display the correct size.
    $newElems.imagesLoaded(function(){
            $(".photoset").each(function() { 
        var newSrc = $(this).attr("src").replace('500','350');
        $(this).attr("src", newSrc);       
    });
}
//This will get the new size of the iframe and resize the iframe holder accordingly.
$newElems.imagesLoaded(function(){
    $(function(){
    var iFrames = $('.photoset');
    function iResize() {
        for (var i = 0, j = iFrames.length; i < j; i++) {
            iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 'px';}
        }

        if ($.browser.safari || $.browser.opera) { 
            iFrames.load(function(){
                setTimeout(iResize, 0); 
            });

            for (var i = 0, j = iFrames.length; i < j; i++) {
                var iSource = iFrames[i].src;
                iFrames[i].src = '';
                iFrames[i].src = iSource;
            }
        } else {
            iFrames.load(function() {
                this.style.height = this.contentWindow.document.body.offsetHeight + 'px';
            });
        }
    });
}

It's working perfectly fine when I go to my blog. 当我转到我的博客时,它的工作正常。
Now we come to my problem: My tumblr uses an infinite scroll plugin . 现在我们来解决我的问题:我的tumblr使用无限滚动插件 And whenever I scroll down, a new bunch of pictures gets loaded and if there is a photoset loaded, it's not resized anymore , it's being displayed in the default size. 每当我向下滚动时,都会加载一堆新照片,并且如果加载了照片集, 将不再调整大小 ,而是以默认大小显示。

I've been searching for a solution for ages, tried to tweak the javascript codes but I don't understand anything of it. 我一直在寻找一种解决方案很久了,试图调整javascript代码,但是我什么都不知道。 The only thing I've found online was this , which is not helping either and I really hope someone can help me here, I'd be more than grateful. 我在网上发现的唯一东西是this ,它也无济于事,我真的希望有人能在这里为我提供帮助,我将不胜感激。

Thank you in advance! 先感谢您!

With infinite scroll you need to apply any methods used on your existing content to your new content, in this case its iFrames() and .photosets . 使用无限滚动时,您需要将现有内容上使用的所有方法应用于新内容,在本例中为iFrames().photosets This can be done via the callback supplied by infinite scroll. 这可以通过无限滚动提供的回调来完成。

As per the documentation ( http://www.infinite-scroll.com/ ): 根据文档( http://www.infinite-scroll.com/ ):

$('#content').infinitescroll({
    navSelector  : "div.navigation",
    nextSelector : "div.navigation a:first",
    itemSelector : "#content div.post" },
    // callback
    function( $newElems ){
    // Do stuff to new posts / $newElems
    });
});

$newElems will contain any new content added to the dom. $newElems将包含添加到dom中的任何新内容。 Now use your methods directly on the new content only. 现在,仅在新内容上直接使用您的方法。

I would suggest reworking iFrames() so it accepts an array of elements, so it can be called more than one. 我建议重做iFrames()以便它接受一个元素数组,因此可以调用多个。

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

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