我使用Shadowbox并且工作正常。 但我不想在点击图片(href)后打开它,需要在pageload上自动打开它。
我可以改变什么呢?
这是 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;
}
答案 0 :(得分: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.