2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jQueryを使用して、スムーズスクロールをVue.jsの構文で書く。

Last updated at Posted at 2017-07-28

Vue.jsのアプリの中にjQueryを共存させる方法です。

jQuery単体よりもスッキリして見やすくなったのではないかと思われます

vueのon:clickでscrollメソッドを呼び出し
scrollの(e)でスクロールする場所を指定しています。

HTML

 <div id="app">
  <a href="#" on:click="scroll('#a')">a</a>       
  <a href="#" on:click="scroll('#b')">b</a>       
  <a href="#" on:click="scroll('#c')">c</a>       
   <div id="a">
   </div>
  <div id="b">
   </div>
  <div id="c">
   </div>
 </div>

Javascript

var app = new Vue({
    el: '#app',
    data: {
    },
    methods: {
        scroll: function(e) {
            $("html,body").animate({
                scrollTop: $(e).offset().top
            }, 500)
        return false;
        }
    }
});
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?