调用draggabilly.pkgd.js
Draggabillly将添加类。#draggable被拖动的元素。
var elem = document.querySelector('#draggable'); var draggie = new Draggabilly( elem, { // options... });
示例代码:
var draggie = new Draggabilly( elem ); function onDragMove( instance, event, pointer ) { console.log( 'dragMove on ' + event.type + pointer.pageX + ', ' + pointer.pageY + ' position at ' + instance.position.x + ', ' + instance.position.y ); } // bind event listener draggie.on( 'dragMove', onDragMove ); // un-bind event listener draggie.off( 'dragMove', onDragMove ); // return true to trigger an event listener just once draggie.on( 'dragMove', function() { console.log('Draggabilly did move, just once'); return true; });