2017-01-26 16 views
1

私はレイアウトとしてヘッダといくつかの画像をコンテンツとして持っています。画像をクリックすると、画面に合わせて拡大表示されます。 jQueryとJSは公正なゲームです。ここに私が何を持っている、私はちょうどそれがpositionの変更のために移行で動作するように得ることができません。またヘッダーをカバーする必要があります。トップ `追加ヘッダの上に配置する画像をクリックして塗りつぶす

$(document).ready(function() { 
 
    $("main img").click(function() { 
 
     $(this).toggleClass("click"); 
 
    }); 
 
});
html, body { 
 
    height:100%; 
 
    margin:0; 
 
    padding:0; 
 
} 
 

 
header { 
 
    height:25%; 
 
    width:100%; 
 
    background-color:blue; 
 
} 
 

 
main { 
 
    display:flex; 
 
    justify-content:space-around; 
 
    flex-wrap:wrap; 
 
} 
 

 
main img { 
 
    padding:1em; 
 
    transition:1s; 
 
} 
 

 
main img.click { 
 
    position:absolute; 
 
    width:100%; 
 
    height:auto; 
 
    padding:0; 
 
    transition:1s; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<header> 
 
</header> 
 
<main> 
 
    <img src="https://placehold.it/100x100"> 
 
    <img src="https://placehold.it/100x100"> 
 
    <img src="https://placehold.it/100x100"> 
 
    <img src="https://placehold.it/100x100"> 
 
    <img src="https://placehold.it/100x100"> 
 
    <img src="https://placehold.it/100x100"> 
 
    <img src="https://placehold.it/100x100"> 
 
    <img src="https://placehold.it/100x100"> 
 
</main>

+0

:0;'画像のための 'css'います。 – NewToJS

答えて

0

$(document).ready(function() { 
 

 
    $("img").click(function() { 
 
     if($(this).width() == "100") { 
 
      $($(this).clone(true)).insertAfter(this); 
 
      $(this).css({"position" : "fixed", "z-index" : "3"}); 
 
      $(this).animate({"width" : $(window).width()-32, "height" : $(window).height()-32, "top" : "0px"}, 1000); 
 
     } 
 
     else { 
 
      $(this).animate({"width" : "0px", "height" : "0px", "top" : ((($(window).height()-32)/2)-50)}, 500, function() { 
 
       $(this).remove(); 
 
      }); 
 
     } 
 
    }); 
 
});
html, body { 
 
    height:100%; 
 
    margin:0; 
 
    padding:0; 
 
} 
 

 
header { 
 
    height:25%; 
 
    width:100%; 
 
    background-color:blue; 
 
} 
 

 
main { 
 
    display:flex; 
 
    justify-content:space-around; 
 
    flex-wrap:wrap; 
 
} 
 

 
main img { 
 
    padding:1em; 
 
} 
 

 
main { 
 
    position:absolute; 
 
    width:100%; 
 
    height:auto; 
 
    padding:0; 
 
} 
 

 
img { 
 
    width: 100px; 
 
    height: 100px; 
 
    z-index: 2; 
 
    position: relative; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<header> 
 
</header> 
 

 
<main> 
 
    <img src="https://placehold.it/100x100"> 
 
    <img src="https://placehold.it/100x100"> 
 
    <img src="https://placehold.it/100x100"> 
 
    <img src="https://placehold.it/100x100"> 
 
    <img src="https://placehold.it/100x100"> 
 
    <img src="https://placehold.it/100x100"> 
 
    <img src="https://placehold.it/100x100"> 
 
    <img src="https://placehold.it/100x100"> 
 
</main>

+0

それは良いですが、私は2つの異なるものを探していました。 1)アニメーションはイメージの元の位置から開始し、2)他のイメージは移動しません。 – thesecretmaster

+0

@thesecretmasterアニメーション化するのはややこしいでしょう。画面いっぱいに画像を左いっぱいにします。 (困難ではありませんが、現実にはそのアニメーションがかなり見えるようにするのは難しいです)アニメーションをページの中央で開始することがありますか? –

+0

@thesecretmasterアニメーション中にイメージが動かず、アニメーションが一貫してページの中央で始まるように、私は自分の答えを編集しました。アニメーションのより良いアイデアを記述できる場合は、 –

関連する問題