0

我使用Shadowbox并且工作正常。但我不喜欢在点击图像(href)后打开它,需要在页面加载时自动打开它。

我可以改变什么来做到这一点?

这是HTML

 <div id="images">
                    <a href="resources/certified_training/1.png" rel="shadowbox[certifiedtraining];width=510;height=372">Image -1</a>
                    <a href="resources/certified_training/2.png" rel="shadowbox[certifiedtraining];width=510;height=372">Image -2</a>
                    <a href="resources/certified_training/3.png" rel="shadowbox[certifiedtraining];width=510;height=372">Image -3</a>
                    <a href="resources/certified_training/4.png" rel="shadowbox[certifiedtraining];width=510;height=372">Image -4</a>
                    <a href="resources/certified_training/5.png" rel="shadowbox[certifiedtraining];width=510;height=372">Image -5</a>
                </div>

这里是 JavaScript

window.onload = function () {
             loadShadowbox();
         };

function loadShadowbox() {
Shadowbox.init({
            showOverlay: false
        });

        window.Shadowbox.setDimensionsOld = window.Shadowbox.setDimensions;
        window.Shadowbox.setDimensions = function (height, width, maxHeight, maxWidth, topBottom, leftRight, padding, preserveAspect) {
            var S = window.Shadowbox;
            window.Shadowbox.setDimensionsOld(height, width, maxHeight, maxWidth, topBottom, leftRight, padding, preserveAspect);
            window.Shadowbox.dimensions.top = 340;
            window.Shadowbox.dimensions.left = 430;
            return window.Shadowbox.dimensions;
        }
4

1 回答 1

1

您最终在窗口加载时初始化了一个 Shadowbox,但没有打开它。完成后,您结束了function loadShadowbox,而是在最后打开 Shadowbox。

编辑:

我已经修改了代码。我实际上错过了一个闭合支架。

function loadShadowbox() {
    Shadowbox.init({
        showOverlay: false
    });

    window.Shadowbox.setDimensionsOld = window.Shadowbox.setDimensions;
    window.Shadowbox.setDimensions = function (height, width, maxHeight, maxWidth, topBottom, leftRight, padding, preserveAspect) {
        var S = window.Shadowbox;
        window.Shadowbox.setDimensionsOld(height, width, maxHeight, maxWidth, topBottom, leftRight, padding, preserveAspect);
        window.Shadowbox.dimensions.top = 340;
        window.Shadowbox.dimensions.left = 430;
        return window.Shadowbox.dimensions;
    }

window.Shadowbox.open();    //Add this line
}  //This is where your `function loadShadowbox()` ends.
于 2013-10-29T10:00:13.833 回答