【问题标题】:colorbox resize interferes with an other script颜色框调整大小会干扰其他脚本
【发布时间】:2017-09-27 12:08:40
【问题描述】:

我在 colorbox 中打开一个 youtube 视频,因为我需要根据视口大小以特定大小打开它,所以我创建了一个函数来计算 colorbox 覆盖大小并在打开时传递它:

overlaysize = overlaySize();

$.colorbox({
    href: url,
    iframe:true, 
    opacity: 0.8, 
    transition: 'none', 
    innerWidth: overlaysize['neww'], 
    innerHeight: overlaysize['newh']
});

在调整大小时,我需要更新尺寸:

$( window ).resize(function() {

    if ( $('#colorbox').length ) {

        overlaysize = overlaySize();

        $.colorbox.resize({
            innerWidth: overlaysize['neww'], 
            innerHeight: overlaysize['newh']
        });

    }

});

但它不起作用。盒子没有调整大小 在同一页面内。我正在使用一个使用颜色框的脚本。 我不确定它是否打印了一些覆盖我的颜色框脚本的代码。

我可以以某种方式引用我的颜色框实例吗?

【问题讨论】:

  • 如果颜色框内的内容在窗口调整大小时自行调整大小,那么只需调用$.colorbox.resize()
  • 如果我删除了其他使用 colorbox 的脚本,我的工作正常

标签: javascript jquery colorbox


【解决方案1】:

我发现的唯一解决方法是在调整大小时关闭颜色框

$( window ).resize(function() {

  if ( $('#colorbox').length ) {

    $.colorbox.close();

  }

});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-05
    • 1970-01-01
    • 1970-01-01
    • 2015-09-13
    • 1970-01-01
    • 2021-12-27
    • 2011-03-07
    • 1970-01-01
    相关资源
    最近更新 更多