給這個小演示中,我已經爲你設置一個嘗試,看看你是否能在項目中切換了HTML類似的東西:
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Demo</title>
<!-- Insert below CSS here -->
<!-- Insert JQuery here (http://code.jquery.com/jquery-latest.min.js) -->
<!-- Insert below JS here -->
</head>
<body>
<div id="shell">
<div id="head">Header.</div>
<div id="slideshow">Slideshow.</div>
<div id="foot">Footer.</div>
</div>
</body>
</html>
CSS:
(主要用於示範):
*{ margin: 0; padding: 0; }
div#head{ height: 200px; background: blue; }
div#foot{ height: 100px; background: red; }
div#slideshow{ height: 300px; background: green; }
JavaScript:
// Fix position initially and on each window resize.
$(window).resize(fix);
$(document).ready(fix);
function fix()
{
// Work out position value.
var base = $("div#slideshow").position().top;
var middle = $(window).height()/2;
var hw = $("div#slideshow").height()/2;
// Position top either at the position determined above, or 0 if it bypasses the top of the page.
var destination = Math.max(middle - base - hw, 0);
$("div#shell").offset({ top: destination });
}
You can grab the full working example here。
用JavaScript/JQuery很容易 - 這是一個選項嗎? – Marty
是的。任何解決方案都是一個很好的解 – Scully
當窗口變小時會發生什麼情況 - 幻燈片放映是否被切斷,或者頁腳是否在摺疊下方? – zenkaty