当前位置: 移动技术网 > IT编程>开发语言>Jquery > 使用[].forEach.call()方法的写拖拽排序。

使用[].forEach.call()方法的写拖拽排序。

2018年07月12日  | 移动技术网IT编程  | 我要评论

---恢复内容开始---

例子:
function registerDrag() {
[].forEach.call(ImgSortable.getElementsByClassName('unload-show'), function (el){
Sortable.create(el, {
group: 'photoGroup',
animation: 1050
});
});
}
要引用两个插件:
  <script src="./jquery.1.12.4.min.js"></script>
  <script src="./Sortable.js"></script>

[].forEach.call的写法理解:
    1.来源 : 是根据 document.querySelectorAll('div')写法扩展的;
   2.[] : 代表的是一个空数组。 作用:用来引出forEach方法,
   3. .forEach : javaScript常用的遍历元素的方法。 作用遍历元素集合(数组)。
    4. .call : 解析:调用对象,并替换掉当前对像。 作用替换对象。
方法解析:
  [].forEach.call() : 遍历数组【替换对象】
  参数:ImgSortable.getElementsByClassName('unload-show'), :替换后的对象【你要遍历的数组名】,
  方法:作用排序
   function (el){
Sortable.create(el, {
group: 'photoGroup',
animation: 1050
});
    el : 形参
    Sortable : 控件的名称。
    .create : 控件的方法
    group(参数) :自定义名称,
    animation : 动画时间

---恢复内容结束---

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网