過去数時間、回答を求めてグーグルで検索してきましたが、同様のインスタンスがstackoverflowに多数表示されましたが、どの回答もうまくいかなかったようです。
初心者/中級ユーザーとしてJQueryを実際に学習/使用しようとしているので、単純なエラーを犯しただけだと思っています。私が取り組んでいるページが、私が望む効果を得るために約 14 の異なる z-index レベルに依存していることは、おそらく役に立たないでしょう。
ファイル フォルダーに少し似たポートフォリオをデザインしようとしています。理想的には、たとえば「アートワーク」を表す div にカーソルを合わせると、色付きの空白の長方形が div の後ろからスライドします。クリックすると、新しいページが読み込まれ、従来のギャラリーが表示されます。
私は2つの異なる方法を試しましたが、動作する結果と動作しない結果が非常に混在しています。head セクションの script タグは次のようになります。
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
function showHiddenDivHover(thechosenone) {
$('div[name|="foliosheet"]').each(function(index) {
if ($(this).attr("id") == thechosenone) {
$(this).slideDown(600);
}
else {
$(this).slideUp(600);
}
});
}
function hideHiddenDivHover(thechosenone) {
$('div[name|="foliosheet"]').each(function(index) {
if ($(this).attr("id") == thechosenone) {
$(this).slideUp(600);
}
else {
$(this).slideDown(600);
}
});
}
$("#info").hover(function () {
$("#info-sheet").slideToggle("slow");
});
$("#artwork").hover(function () {
$("#artwork-sheet").slideToggle("fast");
});
</script>
1 つ目は、randomsnippets.com の Allen Liu のチュートリアルで見つけた例に基づいています。「a」タグの onMouseOver() と onMouseOut() で動作するように設計しました。スタックの一番上の最初の div ではうまくいきましたが、他の 6 ではうまくいきませんでした。ただし、firebug 拡張機能をオンにすると、残りの div が必要に応じて (ほとんど) 表示されるようになりました。
2 番目の手法は、JQuery ドキュメントで見たものと、stackoverflow に関する同様の質問と JSFiddle の例 ( http://jsfiddle.net/nick_craver/JcBAd/など) に基づいていました。
本文の一部の HTML は次のようになります。
<div id="artwork"><a href="#" onMouseOver="javascript:showHiddenDivHover('artwork-sheet')" onMouseOut="javascript:showHiddenDivHover()">
<img src="assets/transparent_long.png" alt="artwork" width="1200" height="35"></a></div>
<div name="foliosheet" id="artwork-sheet"></div>
<div id="artwork"><div id="artwork-sheet"></div></div>
関連する CSS は次のようになります。
#artwork {
z-index: 170;
position: absolute;
height: 500px;
background-repeat: no-repeat;
overflow: hidden;
top: 400px;
width: 1200px;
margin-left: 30px;
border: 2px solid red;
background-image:url(../assets/file_artwork.png);
}
#websites {
background-repeat: no-repeat;
overflow: hidden;
position: absolute;
z-index: 150;
height: 500px;
top: 360px;
width: 1200px;
margin-left: 30px;
background-image:url(../assets/file_websites.png);
}
#threedmodels {
z-index: 130;
position: absolute;
height: 500px;
background-repeat: no-repeat;
overflow: hidden;
top: 320px;
width: 1200px;
margin-left: 30px;
background-image:url(../assets/file_3dmodels.png);
}
#games {
z-index: 110;
position: absolute;
height: 500px;
background-repeat: no-repeat;
overflow: hidden;
top: 280px;
width: 1200px;
margin-left: 30px;
background-image:url(../assets/file_games.png);
}
#movies {
/* border: 2px solid red; */
z-index: 90;
position: absolute;
height: 500px;
background-repeat: no-repeat;
overflow: hidden;
top: 240px;
width: 1200px;
margin-left: 30px;
background-image:url(../assets/file_movies.png);
}
#flash {
z-index: 70;
position: absolute;
height: 500px;
background-repeat: no-repeat;
overflow: hidden;
top: 200px;
width: 1200px;
margin-left: 30px;
background-image:url(../assets/file_flash.png);
}
#info {
z-index: 50;
position: absolute;
height: 500px;
background-repeat: no-repeat;
overflow: hidden;
top: 160px;
width: 1200px;
margin-left: 30px;
background-image:url(../assets/file_info.png);
}
#artwork-sheet {
width: 1100px;
height: 100px;
margin-left: 100px;
background-color:#ff0000;
display: none;
position: absolute;
bottom: 400px;
z-index: 160;
}
#websites-sheet {
width: 1100px;
height: 100px;
margin-left: 100px;
background-color:#006F00;
display: none;
position: absolute;
bottom: 360px;
z-index: 140;
}
#threedmodels-sheet {
width: 1100px;
height: 100px;
margin-left: 100px;
background-color:#0000F5;
display: none;
position: absolute;
bottom: 320px;
z-index: 120;
}
#games-sheet {
width: 1100px;
height: 100px;
margin-left: 100px;
background-color:#E76000;
display: none;
position: absolute;
bottom: 280px;
z-index: 100;
}
#movies-sheet {
width: 1100px;
height: 100px;
margin-left: 100px;
background-color:#80A2AA;
display: none;
position: absolute;
bottom: 240px;
z-index: 80;
}
#flash-sheet {
width: 1100px;
height: 100px;
margin-left: 100px;
background-color:#AE21B1;
display: none;
position: absolute;
bottom: 200px;
z-index: 60;
}
#info-sheet {
width: 1100px;
height: 100px;
margin-left: 100px;
background-color:#0079D6;
display: none;
position: absolute;
bottom: 160px;
z-index: 40;
}
複雑な配置であることは承知していますが、静止画像/divは希望どおりに表示されています。私は自分の小さなプロジェクトで深遠になる傾向がありますが、誰かが手を貸してくれることを願っています.
昨年、私はより多くの自家製/変更されたコードをいじりました。興味のある方はhttp://www.authenticrubydesigns.com/portfolioでご覧いただけます。円形のレイアウトと回転を使用しましたが、処理が遅すぎる場合があり、このままのデザインでは限界があります。たまには新鮮な表情で何の問題もありません。