2

:target-selector での移行について質問があります。私のコードでトランジションを機能させる方法をグーグルでインターネットで検索しようとしましたが、アニメーションしか機能しませんでした(使用は許可されていません)。

私のHTMLコード:

    <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>BluShop</title>
    <link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="container">
    <header id="header">
        <h1>BluShop</h1>
    </header>

    <section id="leftContent">
        <div id="pacificrimContent">
            <h2>Pacific Rim</h2>
            <img src="../bilder/pacificRim.jpg">
            <p>blahblah</p>
        </div>
        <div id="startrekContent">
            <h2>Star Trek</h2>
            <img src="../bilder/starTrek.jpg">
            <p>blahblah</p>
        </div>
        <div id="worldwarzContent">
            <h2>World War Z</h2>
            <img src="../bilder/worldWarZ.jpg">
            <p>blahblah </p>
        </div>
    </section>
    <aside id="rightContent">
        <div id="pacificrimPoster">
            <a href="#pacificrimContent"><img src="../bilder/pacificRim.jpg"></a>
        </div>
        <div id="startrekPoster">
            <a href="#startrekContent"><img src="../bilder/starTrek.jpg"></a>
        </div>
        <div id="worldwarzPoster">
            <a href="#worldwarzContent"><img src="../bilder/worldWarZ.jpg"></a>
        </div>
    </aside>

    <footer id="footer">
    </footer>
</div>  
</body>
</html>

そしてCSSコード:

    @charset "utf-8";
/* CSS Document */

body{
    margin: 0;
    }

#container{
    width: 960px;
    height: 600px;
    margin: auto;
    background-color: rgb(78, 80, 85);
    border: solid 1px rgb(213, 214, 215);
    }

#header{
    height: 60px;
    background-color: rgb(66, 69, 74);
    margin-bottom: 10px;
    }   

#header h1{
    float: left;
    margin: 0px 10px 0px 10px;
    color: rgb(14, 177, 238);   
    }

#leftContent{
    float: left;
    position: relative;
    margin: 0px 10px 10px 10px;;
    height: 460px;
    width: 780px;
    background-color: rgb(230, 231, 232);
    }

#leftContent h2{
    font-size: 20px;
    margin: 10px 0px 0px 10px;
    }

#leftContent img{
    float: left;
    margin: 0px 20px 10px 10px;
    width: 310px;
    height: 420px;
    }

#leftContent p{
    margin: -4px 20px 10px 0px;
    }           

#pacificrimContent, #startrekContent, #worldwarzContent{
    display: none;
    }   

#rightContent{
    float: right;
    width: 140px;
    height: 460px;
    margin: 0px 10px 10px 10px;
    background-color: rgb(230, 231, 232);
    }   

#rightContent img{
    display: block;
    width: 100px;
    margin-left: auto;
    margin-right: auto;
    margin-top: 20px    
    }

#pacificrimContent:target{
    display:block;
    position: absolute;
    }   

#startrekContent:target{
    display:block;
    position: absolute;
    }

#worldwarzContent:target{
    display:block;
    position: absolute;
    }   

#footer{
    height: 60px;
    margin: 0;  
    background-color: rgb(16, 163, 210);
    clear: both;
    }   

:target を使用するときに表示される画像は、最初に非表示にする必要があるため、#pacificrimContent などの下で display: none を使用しています。

だから私が気をつけているのは、#pacificrimContent が表示されるようにトリガーするときに、f.ex のようなトランジション効果が欲しいということです。フェードイン効果。私はさまざまな方法を試しました:トランジションを配置するとき:すべて2sフェードイン。ディスプレイの下: なしですが、うまくいきません。

彼女に向かう途中で誰かが私を助けてくれたらいいのに。また、私が実際に何をしているのか、コピー/パジェを使用していないのかを学ぶことができるように、人々がそれを説明してくれるとうれしいです.

ありがとう!

4

1 に答える 1

0

プロパティを使用するとdisplay(つまり、displayからnoneblockまたはその逆に変更すると)、常にトランジションが中断されます。

別のオプションとしてheight、ブロックの を最初に に設定し、ターゲットに0なったときに に移行することができます。100%以下にサンプルを示します。

#pacificrimContent, #startrekContent, #worldwarzContent {
    height: 0px;
    overflow: hidden;
    transition: height 1s ease-in-out;
}
#pacificrimContent:target, #startrekContent:target, #worldwarzContent:target {
    height: 100%;
    position: absolute;
}

body {
  margin: 0;
}
#container {
  width: 960px;
  height: 600px;
  margin: auto;
  background-color: rgb(78, 80, 85);
  border: solid 1px rgb(213, 214, 215);
}
#header {
  height: 60px;
  background-color: rgb(66, 69, 74);
  margin-bottom: 10px;
}
#header h1 {
  float: left;
  margin: 0px 10px 0px 10px;
  color: rgb(14, 177, 238);
}
#leftContent {
  float: left;
  position: relative;
  margin: 0px 10px 10px 10px;
  height: 460px;
  width: 780px;
  background-color: rgb(230, 231, 232);
}
#leftContent h2 {
  font-size: 20px;
  margin: 10px 0px 0px 10px;
}
#leftContent img {
  float: left;
  margin: 0px 20px 10px 10px;
  width: 310px;
  height: 420px;
}
#leftContent p {
  margin: -4px 20px 10px 0px;
}
#pacificrimContent,
#startrekContent,
#worldwarzContent {
  height: 0px;
  overflow: hidden;
  -webkit-transition: height 1s ease-in-out;
  -moz-transition: height 1s ease-in-out;
  transition: height 1s ease-in-out;
}
#rightContent {
  float: right;
  width: 140px;
  height: 460px;
  margin: 0px 10px 10px 10px;
  background-color: rgb(230, 231, 232);
}
#rightContent img {
  display: block;
  width: 100px;
  margin-left: auto;
  margin-right: auto;
  margin-top: 20px
}
#pacificrimContent:target,
#startrekContent:target,
#worldwarzContent:target {
  height: 100%;
  position: absolute;
}
#footer {
  height: 60px;
  margin: 0;
  background-color: rgb(16, 163, 210);
  clear: both;
}
<div id="container">
  <header id="header">
    <h1>BluShop</h1>

  </header>
  <section id="leftContent">
    <div id="pacificrimContent">
      <h2>Pacific Rim</h2>

      <img src="../bilder/pacificRim.jpg">
      <p>blahblah</p>
    </div>
    <div id="startrekContent">
      <h2>Star Trek</h2>

      <img src="../bilder/starTrek.jpg">
      <p>blahblah</p>
    </div>
    <div id="worldwarzContent">
      <h2>World War Z</h2>

      <img src="../bilder/worldWarZ.jpg">
      <p>blahblah</p>
    </div>
  </section>
  <aside id="rightContent">
    <div id="pacificrimPoster">
      <a href="#pacificrimContent">
        <img src="../bilder/pacificRim.jpg">
      </a>

    </div>
    <div id="startrekPoster">
      <a href="#startrekContent">
        <img src="../bilder/starTrek.jpg">
      </a>

    </div>
    <div id="worldwarzPoster">
      <a href="#worldwarzContent">
        <img src="../bilder/worldWarZ.jpg">
      </a>

    </div>
  </aside>
  <footer id="footer"></footer>
</div>

以下のリンクを使用して、Animatable/Transitionable プロパティのリストを取得します。

  1. W3C リスト
  2. MDN リスト
于 2013-10-10T08:51:04.280 に答える