vue屏幕滚动到一定位置,让某个元素固定

mounted () {
   window.addEventListener('scroll', this.fixedActiveBtn, true)
 },
data () {
    return {
      fixed: false
    }
  },
fixedActiveBtn (e) {
   var scrollTop = e.target.scrollTop
   if (e.target.getAttribute('class') === 'el-main') {
     scrollTop >= 140 ? this.fixed = true : this.fixed = false
   }
 }
<div :class="fixed ? 'phoneBoxfixed':''">div>
.phoneBoxfixed{
  position: fixed !important;
}
.phoneBox{
  position: absolute;
  right: 40px;
  top: 100px;
  width: 400px;
  height: 750px;
 }

你可能感兴趣的:(vue.js,前端,javascript)