How to disappear with the Parallax effect with angular?

Asked

Viewed 104 times

0

How can I disappear with the action of Parallax when it is with an attribute?

this is the tag that has the attribute:

<parallax-image ng-class="{{fixo}}" 
src="/parallax-image/assets/images/image-01.jpg"></parallax-image>

This is the css that has the attribute:

[class^="fixo"] {
  background-color: color($grey, 200);
  background-position: center center;
  background-repeat: no-repeat;
  background-size: cover;
  display: block;
  height: 0;
  overflow: hidden;
  padding-bottom: 40%;
  position: relative;
  width: 100%;
}

And this is you:

if ('.fixo' == true) {
   return true;
} else {
  return false;
}

1 answer

0

Your use of ng-class is wrong. The correct definition would be:

ng-class="{'fixo': meuValor}" //Onde "meuValor" é um $scope do controller ex.: $scope.meuValor

In this case, the class fixo will be added when the $scope.meuValor for true

Another method, if you want to define a OR class based on the same value, would be:

ng-class="meuValor ? 'fixo' : 'nao-fixo'"

In this case if the $scope.meuValor for true will be added to the class fixo, if the class will not be added nao-fixo.

Note then that your JS should change to something similar to this:

if( 'algum comparativo') {
    $scope.meuValor = true;
else {
    $scope.meuValor = false;
}

Since you didn’t provide much information, this part of logic depends on your context, but with this information I believe you can solve the problem.

  • Hello Celsom I put it this way: the script looks like this: <script> Scope.haseffect = true; Scope.haseffect = (Scope.haseffect === 'false') ? false : Scope.haseffect; </script>

  • And the html looks like this: <div ng-class="{'Parallax-image-{{index}}': haseffect, 'Fixed': ! haseffect}" ng-if="src"> <div class="Parallax-image-overlay" ng-if="alt" horizontal layout center-Justified fit> <p>{{alt}}</p> </div> </div>

  • But it seems that css is not loading.

  • @Are you putting that script directly into the body of the page? If so, it won’t even work. Must be linked to a controller (or Directive - or other equivalent method),

  • It is linked to a controler yes @Celsomtrindade...so I put the code for you to see... The script is working from what I saw on the console, but the css I created for Fixed it is not returning.

  • Check that the class Fixed is being added to the element. If it is not, make sure that the value of hasEffect is being updated because the statement seems to me all right.

Show 1 more comment

Browser other questions tagged

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