change soon by decreasing screen width

0

I would like that when the site was seen in mobile the logo appeared smaller, I have two logos, logo1 (major) and logo2 (minor), as I do when the site is opened on a device with screen up to 800px wide logo1 is exchanged calls logo2

logo1

<img  id="minhaImagem" src="img/logo1.png" Alt="logo">

.

. ... jquery code ...

.

.

Thanks to anyone who can help

    
asked by anonymous 11.02.2017 / 02:00

3 answers

1

Use the CSS Media Queries to change the display / layout of the elements depending on the screen size.

When a media query is true, the style layer or corresponding style rules are applied. More information on MDN

For your case, create a div with class logo , in css inform the background with the logo image. Ex.:

HTML:

<div class="logo"></div>

CSS:

<style>

/* Regra geral */
.logo {
    background-image: url("img/logo1.png");
}

/* Regra aplicada quando a largura da tela estiver entre 0px e 800px */
@media (max-width: 800px) 
{
  .logo{
    background-image: url("img/logo2.png");
  }
}

</style> 
    
11.02.2017 / 02:28
1
$(window).on('load', function() {

  if (window.screen.width < 800) { 

    $('#minhaImagem').attr('src','img/logo2.png');

  }

});

Only with CSS you can too. But with jquery can do so.

    
11.02.2017 / 02:24
0

MEDIA QUERY

The method for working with screen widths and responsiveness is CSS Media Query , and you can be applied as follows:

img {
  transition: 0.52s all;
  padding: 25px;
  display: block;
  width: 100px;
  height: 100px;
}

img#minhaImagem2 {
  width: 0px;
  height: 0px;
  padding: 0px;
  opacity: 0;
}

/* Fiz com 500px para poder testar, mas é só trocar para 800px */
@media screen and (max-width: 500px) {
  img#minhaImagem2 {
    width: 100px;
    height: 100px;
    padding: 25px;
    opacity: 1;
  }
  
  img#minhaImagem {
    width: 0px;
    height: 0px;
    padding: 0px;
    opacity: 0;
  }
}
<img  id="minhaImagem" src="img/logo1.png" Alt="logo">
<img  id="minhaImagem2" src="img/logo1.png" Alt="logo 2">
    
11.02.2017 / 02:24