1

So i am trying to create a parallax effect by targeting background-position with a data object.

<div class="parallaxBanner" :style="{scrollBanner}">
</div>

<script>
    export default {
        data: function(){
            return{
                scrollBanner: 0,
            }
        },
        methods:{
            scrollPosition: function(){
                this.scrollbanner = window.scrollY % 0.5;
                console.log(window.scrollY);
            }
        },
        mounted() {
          window.addEventListener('scroll', this.scrollPosition);
        }
    }
</script>

not 100% how to target css in line value any suggestions would be a big help :)

2

2 Answers 2

1

If you want to set background-position, you can use

<div class="parallaxBanner" :style="{ backgroundPosition: scrollBanner }">
</div>
Sign up to request clarification or add additional context in comments.

Comments

0

You can directly assign method in style and write one method in computed:

HTML

<Row>
  <i-col :span="5" :style="styles" class="sidebar">
    <f-sidebar></f-sidebar>
  </i-col>
</Row>

SCRIPT

computed: {
  styles () {
    return {
      style.position = 'fixed'
      style['z-index'] = '99'
      style.height = '100%'
      style.background = '#363e4f'
    }
  }
}

Comments

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.