2012-10-31 102 views
1

我试图破解我的方式进入tumblr photoset,我想我找到了最大700显示大小的修复。Tumblr Photoset

让我们说,这是由{Photoset-700}产生的正常的iframe:

<iframe class="photoset" scrolling="no" frameborder="0" height="1048" width="700" style="border:0px; background-color:transparent; overflow:hidden;" src="http://www.georgefratila.ro/post/20314734048/photoset_iframe/esssk/tumblr_m1tp5634Si1qzc7t7/700/false"></iframe> 

有没有办法来改变iframe的宽度,改变src网址的最后一部分,放大时保持宽高比?

宽度= “700” 改变这个值到860 SRC = “http://www.georgefratila.ro/post/20314734048/photoset_iframe/esssk/tumblr_m1tp5634Si1qzc7t7/700/false” 改变的最后部分src/700/false转换为/ 860/false

我觉得我看到它在网站上用jquery制作,但我不记得名字,我会研究我的历史,也许我会找到它。

感谢您的帮助。

Edit.1 我想我排序的几乎一切:

 $('iframe.photoset').each(function() { 
     $(this).attr("width", function(index, old) { 
            return old.replace("700", "860"); 
      }); 
      $(this).attr("src", function(index, old) { 
            return old.replace("/700/false", "/860/false"); 
      }); 
}); 

,我现在唯一的问题是高度,它不规模,以适应的iframe。

回答

1

这似乎来了很多。我开发了一个jQuery插件,使Tumblr Photosets能够完全响应,并且可以设置任何宽度来设置容器。 https://github.com/PixelUnion/Extended-Tumblr-Photoset

我更喜欢用这种方式来处理iFrame的尺寸,因为你可以获得更多的信息(包括EXIF数据),并且可以完全控制内容。

0

我已经找到了解决我的问题,那就是:

//This will change the source address and display the correct size. 

     $(".photoset").each(function() { 
    var newSrc = $(this).attr("src").replace('700','860'); 
    $(this).attr("src", newSrc);  
}); 
//This will get the new size of the iframe and resize the iframe holder accordingly. 

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

如果您有关于如何最大限度地减少或改善脚本请在下面张贴的任何想法。享受