/* animation 对象要发生的动画 数组*/ /* option 对象 */ /* targetele 动画发生的目标对象 dom对象或其集合 */ /* funcall 回调函数 执行动画后将要执行的操作有一个参数为 触发动画的对象 */ /* threshold 元素在视口中所占的比例 */ const scrl = ( arg = { option: null, targetele: null, animation: null, funcall: null } ) => { if (arg.animation == null) { throw error("error in effect parameter"); } else if (arg.targetele == null) { throw error("the target object was passed in incorrectly"); } else { if (window.intersectionobserver) { var callback = (en) => { en.foreach(element => { if (element.isintersecting) { var ele = element.target; ele.style.animation = arg.animation; observer.unobserve(ele); if (arg.funcall) arg.funcall(ele); } }); } const observer = new intersectionobserver(callback, arg.option); observer.observe(arg.targetele); } else { throw error("intersectionobserver are not compatible"); } } } const scan = ( arg = { option: null, targetele: null, animation: null, funcall: null } ) => { if (arg.animation == null) { throw error("error in effect parameter"); } else if (arg.targetele == null) { throw error("the target object was passed in incorrectly"); } else { if (window.intersectionobserver) { opt = { threshold: [arg.option] } var callback = (en) => { en.foreach(element => { if (element.isintersecting) { var ele = element.target; ele.style.animation = arg.animation; observer.unobserve(ele); if (arg.funcall) arg.funcall(ele); } }); } const observer = new intersectionobserver(callback, opt); observer.observe(arg.targetele); } else { /* arg.targetele.style.opacity = "1"; */ throw error("intersectionobserver are not compatible"); } } }