0

私はWebデザインとスクリプティングにまったく慣れていません。上部にバナーフレーム、左側にメニュー、右下の大きなセクションにメインコンテンツがあるサイトを構築しようとしています。バナーのサイズをブラウザのサイズに合わせて動的に調整したい。IE8でこれを達成しましたが、IE9で正しく表示されません。さらに、現在iframeを試しているフレームの境界を越える背景画像が必要でしたが、ブラウザーウィンドウ全体に表示させることはできません。ときどき、iframeのサイズや位置を動的に変更することはできますが、信頼性は高くありません。さまざまな位置タイプを試したほか、iframeをラップして、サイズ変更と配置も試みました。これは私が持っている中で最も成功したコードであり、失敗した試行の残り物であるため、冗長で参照されていないコメント付きのコードを許します。

<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>Mountain Girl Gallery</title>
<style media="screen" type="text/css">
<!--
#layer1 { position: absolute; top: 0px; left: 0px; width: 1000px; height: 95px; visibility: visible}
--!>
<!--
#layer2 { position: absolute; top: 95px; left: 500px; width: 100px; height: 505px; visibility: visible}
--!>
<!--
#layer3 { position: absolute; top: 95px; left: 100px; width: 900px; height: 505px; visibility: visible}
--!>
</style>
<script type="text/javascript">
function frameResize(){
var winW;
var winH;
if (document.body && document.body.offsetWidth) {
winW = document.body.offsetWidth;
winH = document.body.offsetHeight;
}
if (document.compatMode=='CSS1Compat' &&
document.documentElement &&
document.documentElement.offsetWidth ) {
winW = document.documentElement.offsetWidth;
winH = document.documentElement.offsetHeight;
}
if (window.innerWidth && window.innerHeight) {
winW = window.innerWidth;
winH = window.innerHeight;
}

var bframe=document.getElementById('bannerframe');
//var menuframe=document.getElementById('menu');
var mframe=document.getElementById('main');

//var f1=document.getElementById('bannerframe');
//var f2=document.getElementById('menu');
//var f3=document.getElementById('main');

bframe.style.width=winW;
bframe.style.height=winH*.2;
//menuframe.style.width=winW*.15;
//menuframe.style.height=winH*.8;
//menuframe.style.top=(winH*.2)+"px";
mframe.style.width=winW*.85;
mframe.style.height=winH*.8;
mframe.style.top=(winH*.2)+"px";
mframe.style.left=(winW*.15)+"px";

//f1.style.width=bframe.style.width;
//f1.style.height=bframe.style.height;
//menuframe.style.width=winW*.15;
//menuframe.style.height=winH*.8;
//f2.style.top=menuframe.style.top;
//f3.style.width=mframe.style.width;
//f3.style.height=mframe.style.height;
//f3.style.top=mframe.style.top;
//f3.style.left=mframe.style.left;
}
</script>
<script type="text/javascript">
function setSize(){
frameResize();
if(window.attachEvent)
window.attachEvent("onresize",frameResize);
else if(window.addEventListener)
window.addEventListener("resize",frameResize,false);
}
</script>
</head>
<body
style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); background-image: url(mountain%20girl%20background.JPG); background-attachment: fixed; background-position: 50%; height: 657px;"
onresize="frameResize()">
<div align="center">
<iframe style="position: absolute; top: 0px; left: 0px; width: 1000px; height: 200px;"
src="banner.html" name="bannerframe" id="bannerframe" allowtransparency="true" frameborder="0"></iframe></div>

<iframe style="position: relative; top: 200px; left: 0px;"
src="menu.html" name="menu" id="menu" allowtransparency="true"
frameborder="0"></iframe>
<iframe style="position: relative; top: 200px; left: 150px; width: 850px; height: 505px;"
src="home.html" name="main" id="main" allowtransparency="true" onload="setSize()" frameborder="0"></iframe>
</body>
</html>

私は他の提案を受け入れていますが、サーバーサイドスクリプトを使用したくありません。

4

1 に答える 1

0

さて、今日ではiframeの使用はお勧めしません(フレーム:絶対にありません!)そこで、数年前に、 ajaxを使用してリフレッシュせずにコンテンツをロードする方法の例を作成しました。このようにして、CSS をより詳細に制御し、後で他のコードと組み合わせることができます。

乾杯。

PS: あなたの作品をチェックするためのリンクを設定できれば、私は素晴らしいです!.

于 2012-06-07T04:00:29.363 に答える