Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

vue on page link or anchor

// scroll to element using quasar library

// uses example; scrollToElement(this.$route.hash)
// uses example; scrollToElement('#cafe-menu')


import { scroll } from 'quasar'
const { getScrollTarget, setScrollPosition } = scroll

    scrollToElement (id) {
      if (id && id !== '') {
        let el = document.querySelector(id)
        if (el) {
          const target = getScrollTarget(el)
          const offset = el.offsetTop
          const duration = 1000
          setScrollPosition(target, offset, duration)
        }
      }
    },
Comment

vue on page link or anchor


// uses example; scrollToElement(this.$route.hash)
// uses example; scrollToElement('#cafe-menu')


scrollToElement (id) {
  // takes input id with hash
  // eg. #cafe-menu
  const el = document.querySelector(id)
  el && el.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "nearest" })

}
Comment

vue on page link or anchor

//P.S. the code is written for Vue 2.
//You will have to adjust it to Vue 1.

//Your view:
// <a class="porto-button" @click="scrollMeTo('porto')">Porto, Portugal</a>
// ...
// <div ref="porto" class="fl-porto"> </div>




//Your code:
methods: {
  scrollMeTo(refName) {
    var element = this.$refs[refName];
    var top = element.offsetTop;

    window.scrollTo(0, top);
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: req.header express.js 
Javascript :: plus operator javascript 
Javascript :: add new element by index js 
Javascript :: how to display a calender in react native 
Javascript :: destructuring an array 
Javascript :: Sets can be used to store __________. in js 
Javascript :: discord.js vs discord.py 
Javascript :: how to link js function to button 
Javascript :: javascript pipe async functions 
Javascript :: remove two things from javascript string 
Javascript :: how to sort string alphabetically in javascript 
Javascript :: javascript format a date 
Javascript :: html form action javascript method 
Javascript :: AJAX in reload a div container 
Javascript :: vue component naming convention 
Javascript :: throw new error( 
Javascript :: how to set array in javascript 
Javascript :: date formatting javascript 
Javascript :: npx for yarn 
Javascript :: use of slot in vue 
Javascript :: string en javascript 
Javascript :: javascript block link action 
Javascript :: tailwind only dropdown 
Javascript :: N-dim object support meanigh 
Javascript :: code for random dom background image change 
Javascript :: where to import guards in angular 
Javascript :: get all visible text on website javascript 
Javascript :: useMatch 
Javascript :: Return a sorted array without mutating the original array JS Javascript Free Code Camp FCC 
Javascript :: save action hide element in jquery 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =