3

I pretty new in CSS/Javascript and i'm trying to do an animation where i'm zooming out in a photo and adding a text, it's basically working but i have a glitch at the beginning that i don't understand how to get rid of it...

You can also find this code on CodePen.io or GitHub Gist

I hope my description is clear enough, thanks in advance for any input !

var x = document.getElementById("img_txt");

// if (x) {
  x.addEventListener("mouseover", func, false);
  x.addEventListener("mouseout", func1, false);
// }

function func()
{
   document.getElementById("toto").setAttribute("style", "display:block;")
}

function func1()
{
    document.getElementById("toto").setAttribute("style", "display:none;")
}
.voyages {

     height: 400px;
  	 width: 100%;
  	 margin: 0 auto;
  	 padding: 20px 0px 10px 0px;
  	 display: flex;
  	 justify-content: center;
  	 align-items: center;
  	 overflow: hidden;

}

img.imgvyge {

    border-radius: 50%;
    object-fit: cover;
    width: 300px;
    height: 300px;
    justify-content: center;
    align-items: center;
    margin: auto 30px;
    -webkit-transition: all 1s ease;
    -moz-transition: all 1s ease;
    -o-transition: all 1s ease;
    -ms-transition: all 1s ease;
    transition: all 1s ease;
  }

.imgvyge:hover {

    width: 400px;
    height:400px;

  }

p.text {

    display: none;
    z-index:100;
    position:relative;
    color:black;
    font-size:24px;
    font-weight:bold;
    left:130px;
    bottom:160px;
    /*-webkit-transition: all 0.7s ease;*/
    transition: all 0.7s ease;

  }
<section class="voyages">
  <a id="img_txt" class="anchorvyge" href="#">
      <img class="imgvyge" src="https://unsplash.it/1600/900/?random" alt="vyge1"></img>
      <p id="toto" class="text">YOPYOP</p>
  </a> 
</section>

2
  • what type of glitch are you facing? i m sorry but still unclear Commented Oct 17, 2016 at 5:43
  • Sorry if it was not clear enough it's when you mouse over the image, it jump a bit then start the animation properly the solution below propose by @asifuzzman is fixing my problem Thanks ! Commented Oct 18, 2016 at 15:49

1 Answer 1

2

I think your height is making the problem and you talked about this glitch that image jumped at the first place when you hover the mouse.just Make it 100% .hope it helps.

var x = document.getElementById("img_txt");

// if (x) {
  x.addEventListener("mouseover", func, false);
  x.addEventListener("mouseout", func1, false);
// }

function func()
{
   document.getElementById("toto").setAttribute("style", "display:block;")
}

function func1()
{
    document.getElementById("toto").setAttribute("style", "display:none;")
}
.voyages {

     height: 100%;
  	 width: 100%;
  	 margin: 0 auto;
  	 padding: 20px 0px 10px 0px;
  	 display: flex;
  	 justify-content: center;
  	 align-items: center;
  	 overflow: hidden;

}

img.imgvyge {

    border-radius: 50%;
    object-fit: cover;
    width: 300px;
    height: 300px;
    justify-content: center;
    align-items: center;
    margin: auto 30px;
    -webkit-transition: all 1s ease;
    -moz-transition: all 1s ease;
    -o-transition: all 1s ease;
    -ms-transition: all 1s ease;
    transition: all 1s ease;
  }

.imgvyge:hover {

    width: 400px;
    height:400px;

  }

p.text {

    display: none;
    z-index:100;
    position:relative;
    color:black;
    font-size:24px;
    font-weight:bold;
    left:130px;
    bottom:160px;
    /*-webkit-transition: all 0.7s ease;*/
    transition: all 0.7s ease;

  }
<body>
<section class="voyages">
  <a id="img_txt" class="anchorvyge" href="#">
      <img class="imgvyge" src="https://unsplash.it/1600/900/?random" alt="vyge1"></img>
      <p id="toto" class="text">YOPYOP</p>
  </a> 
</section>
</body>

Sign up to request clarification or add additional context in comments.

2 Comments

effectively working ! Now have to look at it more closely to understand this behaviour.
glad to help :) .your height was fixed at the first place thats why it got conflicted and took a little bump while animating .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.