Leave softer effect

Asked

Viewed 368 times

0

How I make this effect softer?

$j(window).scroll(function () {
    console.log($j(document).scrollTop());
    if ($j(document).scrollTop() >= 300) {
        $j('.logo img').attr('src', 'http://i.imgur.com/499DSOf.png').addClass('logozinho');
        $j('.header-container').css({"borderTop":"none";})
    } else {
        $j('.logo img').attr('src', 'http://roupasatacado.dev.bizcommerce.com.br/media/wysiwyg/LOGO/loja-logo_1_.png').removeClass('logozinho');
        $j('.header-container').css({"borderTop":"1.5rem solid rgba(67, 67, 67, 0.12)"});
    }
}); 

If it were, for example, a toggle effect, it would only put the "speed" in MS that would be good, but in the case of this code, can you make it softer? Switching from one effect to the other...

  • Which parameter you want to soften? borderTop?

  • In this case, everyone there. The SRC exchange, which in this case will change the image, and did not want to leave that business "dry" and the edge too. When adding and removing the edge, also wanted to make it softer.

1 answer

4


Maybe the animate() jquery whatever you’re looking for, it executes a custom animation of CSS properties, follow an example in your context:

$( ".header-container" ).animate({
    borderTop: none
  }, 5000, function() {
    // animação completa.
});

And a snippet also containing a way to smooth the change of attribute src with the method fadeOut() jquery:

$("#go").click(function() {
  $("#block").animate({
    width: "70%",
    opacity: 0.4,
    marginLeft: "0.6in",
    fontSize: "3em",
  }, 1500);
});


$("#go2").click(function() {
  $("img").fadeOut('slow', function() {
    $("img").attr('src', 'https://www.stoughtonutilities.com/images/TOD-clock.jpg');
    $("img").fadeIn('slow');
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="go">Animar</button>
<div id="block">Olá!</div>

<button id="go2" style="position:absolute;">Suavizar Troca Src</button>
<image id="img" style="margin-top:30px;" src="https://c.tadst.com/gfx/sunrise.png">

  • Thanks Mathias, for the reply again. But the exchange of SRC there, I also wanted to "soften", would be also with the Animate(), case this?

  • 1

    @Lucascarvalho added the answer a way to smooth the SRC exchange as well.

  • Thanks Mathias, but it’s giving error, is giving "None is not defined" I did so: $j(window). scroll(Function() { console.log($j(Document).scrollTop(); if ($j(Document).scrollTop() >= 300) { $j('.logo img').attr('src', 'http://i.imgur.com/499DSOf.png').addClass('logozinho'); $j('.header-container'). Animate({ borderTop: None }, 300); } Else { $j('.logo img'). attr('src', 'http://roupasatacado.dev.bizcommerce.com.br/media/wysiwyg/LOGO/loja-logo_1_.png'). removeClass('logozinho'); } }); I use $j because we also use prototype.

  • 1

    @Lucascarvalho next, I will try to edit the answer so that the example is as close to what you need.

  • Thank you very much, sorry I’m still layman, I’m still studying, and thank you for your patience!

  • @Lucascarvalho no problem, we are here p/ this, follow a fiddle with the logo smoothing, note that I do not use $j and yes $, compared to the border I’m going to owe you, I could not change only the border-top (in a gentle way) with Animate, I hope it helps.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.