import Vue from 'vue'
export default {}

/**
 *   ----  描点指令  ---- v-anchor
 * @param  {Object} anchorObj 值为绑定的描点Id和 向上偏移值(可选) 例：{ bindVal: #anchor, topVal: 90}
 */

Vue.directive('anchor', {
	inserted: function(el, binding) {
		console.log('88888888')
		let topVal = binding.value.topVal ? binding.value.topVal : 0
		// el.onclick = function () {
		//     document.documentElement.scrollTop = $(binding.value.bindVal).offset().top - topVal
		// }
		/* el.addEventListener('touchstart', function () {
			setTimeout(() => {
				$('html, body').animate({
					scrollTop: $(binding.value.bindVal).offset().top - topVal
				}, {
					duration: 200,
					easing: 'swing'
				})
				// document.documentElement.scrollTop = $(binding.value.bindVal).offset().top - topVal
			}, 200)
		}, true)*/
		wx.createSelectorQuery().select(`'${binding.value.bindVal}'`).boundingClientRect().exec(function(res) {
			let height = res[0].height
			console.log('88888888')
			console.log(binding.value.bindVal)
			console.log(height)
		})
	}
})

