0

さて、私はこのウェブページを書き始めていますが、答えがまったく見つからないいくつかの問題に遭遇しました。

私が持っているコードの基本的な考え方は次のとおりです。

  1. マウスが「ウェブページを探索」上にあるときにメニューを開く
  2. マウスオーバーでメニュー「リンク」が強調表示される
  3. ユーザーがメニュー項目をクリックすると、メニューがページの上部に移動し、ユーザーが別のリンクをクリックするまで「リンク」が強調表示されたままになります。
  4. メニューが一番上に移動すると、その下に div が開き、そのセクションのコンテンツが表示されます。

私は2つの主な問題を抱えています。まず、メニュー項目をクリックするたびに、強調表示されたままになりません (番号 3)。次に、クリックした後、メニューの下に div が表示されません (番号 4)。これらの問題についての洞察をいただければ幸いです。

すべての問題に関連していると思われるため、すべてのコードを含めています。

<!DOCTYPE html>
<html>
<head>
<style>
body
{
    background-color: #000000;
}
#container
{
    z-index: -1;
    background: #000000;
    width: 900px;
    height: 900px;
    position: absolute;
    top: 0px;
    left: 50%;
    margin-left: -450px;
}
#explore
{
    z-index: 1;
    background: #000000;
    width: 300px;
    height: 150px;
    position: absolute;
    top: 41.666%;
    left: 33.333%;
    opacity: 1;
}

#explore-text
{
    z-index: 1;
    color: #eb56bd;
    font-size: 50px;
    font-family: sans-serif;
    font-weight: bold;
    text-align: center;
    position: absolute;
    top: 5px;
    left: 0%;
    opacity: 1;
}
.title
{
    z-index: 2;
    width: 300px;
    height: 150px;
    text-align: center;
    font-size: 60px;
    font-family: sans-serif;
    font-weight: bold;
    color: #000000;
    display: none;
}
#news
{
    background: #eb56bd;
    position: absolute;
    top: 41.666%;
    left: 33.333%;
}
#about
{
    background: #eb56bd;
    position: absolute;
    top: 41.666%;
    left: 0%;
}
#events
{
    background: #eb56bd;
    position: absolute;
    top: 41.666%;
    left: 66.666%;
}
.content
{
    z-index: 0;
    background: #b0408d;
    width: 900px;
    position: absolute;
    top: 21.666%;
    left: 0px;
    height : 900;
}
#news-content
{
    display: none;
}
#about-content
{
    display: none;
}
#events-content
{
    display: none;
}
</style>
</head>
<body>
<div id="container">
<div id="explore" onmouseover="overExplore()" onmouseout="outExplore()">
<div id="explore-text">Explore Webpage</div>
</div>
<div id="news" class="title" onmouseover="overTitle(news)" onmouseout="outTitle(news)" onclick="titleClick(news)">news</div>
<div id="about" class="title" onmouseover="overTitle(about)" onmouseout="outTitle(about)" onclick="titleClick(about)">about</div>
<div id="events" class="title" onmouseover="overTitle(events)" onmouseout="outTitle(events)" onclick="titleClick(events)">events</div>
<div id="news-content" class="content">

</div>
<div id="about-content" class="content">

</div>
<div id="events-content" class="content">

</div>
</div>
<script>
var titleClicked = false;
var isClicked;
var newsContent = document.getElementById('news-content');
var aboutContent = document.getElementById('about-content');
var eventsContent = document.getElementById('events-content');
var title = document.getElementsByTagName('title');
var news = document.getElementById('news');
var about = document.getElementById('about');
var events = document.getElementById('events');
var explore = document.getElementById('explore');
var exploreText = document.getElementById('explore-text');
function overExplore() {
    explore.style.width="900px";
    explore.style.left="0%";
    explore.style.background="#eb56bd";
    explore.style.cursor="pointer";
    explore.style.cursor="hand";
    explore.style.opacity="0";
    news.style.display="block";
    about.style.display="block";
    events.style.display="block";
}
function outExplore() {
    explore.style.width="300px";
    explore.style.left="33.333%";
    explore.style.background="#000000";
    exploreText.style.left="0%";
    exploreText.style.top="5px";
    explore.style.opacity="1";
    news.style.display="none";
    about.style.display="none";
    events.style.display="none";
}

function overTitle(div) {
    if (div!= isClicked) {
        div.style.background="#b0408d";
    }
    if (titleClicked == false) {
    div.style.display="block";
    news.style.display="block";
    about.style.display="block";
    events.style.display="block";
    }
    explore.style.cursor="pointer";
    explore.style.cursor="hand";
}
function outTitle(div) {
    if (div!= isClicked) {
        div.style.background="#eb56bd";
    }
    if (titleClicked == false) {
        div.style.display="none";
        news.style.display="none";
        about.style.display="none";
        events.style.display="none";
    }
}
function titleClick(div) {
    div.style.background="#b0408d";
    var isClicked = div;

    if (div == news) 
    {
        about.style.background="#eb56bd";
        events.style.background="#eb56bd";
        newsContent.style.display="block";
        aboutContent.style.display="none";
        eventsContent.style.display="none";
    }
    else if (div == about)
    {
        news.style.background="#eb56bd";
        events.style.background="#eb56bd";
        newsContent.style.display="none";
        aboutContent.style.display="block";
        eventsContent.style.display="none";

    }
    else
    {
        news.style.background="#eb56bd";
        about.style.background="#eb56bd";
        newsContent.style.display="none";
        aboutContent.style.display="none";
        eventsContent.style.display="block";
    }
    explore.style.top="5%";
    news.style.top="5%";
    about.style.top="5%";
    events.style.top="5%";
    titleClicked=true;
}
</script>    
</body>
</html>    

どうもありがとうございました。

二次的な問題: メニューのテキストにカーソルを合わせたときにカーソルがポインターから変化しないようにするにはどうすればよいですか?

もう一度ありがとう!

4

2 に答える 2

1

疑似クラス ( など:hover) を希望どおりに動作させることはできませんでした。jQuery を使用できる場合は、メニュー クラスにクリック関数を追加できます。

$('.title').click(function() {
$('.title').css({'background':'#eb56bd'});
$(this).css({'background':'#b0408d'});
});

まず、すべての背景をクリックされていない色に設定してから、クリックされたアイテムにハイライト色を適用します。これにより、別のアイテムをクリックしたときに、以前にクリックしたアイテムのハイライトが削除されます。

JSFiddle

于 2013-11-10T08:02:11.267 に答える
1

メニュー リンクのスタイルを設定するには、css クラスを使用する必要があります。

.selected{background:rgb(176, 64, 141);}

メニュー リンクがクリックされると、選択したクラスがそのメニュー リンクに適用されます。

function titleClick(div) {
   //div.style.background="#b0408d";
   div.className='selected';
   var isClicked = div;

次に、他のメニュー リンクから「選択された」クラスをクリアして、それらが選択されないようにする必要があります。次に例を示します。

about.className="";
events.className="";

mouseover と mouse out を使用してメニュー リンクのスタイルを設定する代わりに、代わりに css :hover を使用します。

#news:hover{
    background:"#eb56bd";
}

divが表示されないのは、divが空だからだと思います。ランダムなテキストで埋めましたが、表示されます。

于 2013-11-10T04:38:54.687 に答える