nhayder
218
2
Vue

Scroll page to page to section with maching ID

Posted 3 months ago by nhayder

on my blade page i have multiple sections with marked with ID

// this is the section
              <section class="flex flex-col justify-center relative widget-bg-image" 

                v-for="(widget, index) in widgets" :key="widget.id" 

                :class="[ wCornerTL(widget), wCornerTR(widget) ]"

                :id="widget.id"

              >

When an event is triggered i'm passing the ID of the section i need to scroll the page to?

  created(){

    Event.$on('requestToScrollPageDown', (id) => {
        
          var ele = document.getElementById(id);

          var maxid = 0;

          ele.map(function(obj){   

              if (obj.id > maxid) maxid = obj.id;

          });

          window.scrollTo(maxid.offsetLeft,maxid.offsetTop); 

    });

the code above is returning error


Vue warn]: Error in event handler for "requestToScrollPageDown": "TypeError: Cannot read property 'map' of null"

so my question is how to make the scrolling to work???

Please sign in or create an account to participate in this conversation.