2013-02-19 81 views
1

我想打开colorbox onclick。没关系。但是现在我想将colorbox高度设置为auto(根据返回的内容高度的高度),并且浏览器的滚动条将在colorbox内容高度的高度范围内滚动。这里是我的代码如何在jQuery的colorbox中设置自动高度?

$('body').on('click', 'a.post', function(e) { 
    e.preventDefault(); 
    $.colorbox({ 
    width: "850px", 
    height: "600px", 
    iframe: true, 
    href:this.href 
    }); 
}); 

任何帮助? (在此先感谢)

+0

我试图从颜色框的网站这部分代码,但没有解决 $( 'a.post')colorbox.resize()。 – rafi 2013-02-19 08:20:06

+0

如果你想自动调整高度,为什么它设置为600px? – andyb 2013-02-19 08:22:40

+0

@andyb - 我试图做到这一点没有高度选项,但它然后获得约30至40像素的高度。这就是为什么...... – rafi 2013-02-19 08:25:18

回答

3

您可以尝试通过height()方法利用身高:

var objHeight=$(window).height()-100; // reduce 100, so that it will fit in the container 

$.colorbox({ 
    width: "850px", 
    height: objHeight, 
    iframe: true, 
    href: this.href 
}); 
+0

如果我给出任何参考,可能会有所帮助。实际上,我正在尝试像pinterest.com一样做模态窗口。 @anydb – rafi 2013-02-19 08:51:58

+0

你的答案是有帮助的,但不是我想要做的。 – rafi 2013-02-19 09:01:30

1

发布对于那些谁可能仍然有这个问题

对于汽车的高度,这个美丽的工作对我的回答,

<script type="text/javascript"> 
    function openColorBox() { 
     $.colorbox({ 
      href: "Something.aspx", 
      onComplete: function() { 
       $(this).colorbox.resize(); 
      } 
     }); 
    } 
</script>