Answer the question
In order to leave comments, you need to log in
How to translate this jQuery syntax into Vue?
How to translate this jQuery syntax into Vue?
$(window).on("scroll", function () {
var scrolled = $(this).scrollTop();
if( scrolled > 107 ) {
$('.content').addClass('scrolled');
}
if( scrolled <= 107 ) {
$('.content').removeClass('scrolled');
}
});
Answer the question
In order to leave comments, you need to log in
Let's add a property to the component that will contain the current scroll value:
data: () => ({
scroll: 0,
...
}),
created() {
window.addEventListener('scroll', () => this.scroll = window.scrollY);
},
computed: {
scrollClasses() {
return что-то, в зависимости от значения this.scroll;
},
...
},
<div :class="scrollClasses"></div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question