效果图:
直接上代码
* {
margin:0;
padding:0;
list-style:none
}
#ul1 {
width:660px;
position:relative;
margin:10px auto;
}
#ul1 li {
width:200px;
height:150px;
float:left;
list-style:none;
margin:10px;
}
#ul1 li:hover {
border-color:#9a9fa4;
box-shadow:0 0 6px 0 rgba(0,0,0,0.85);
}
#ul1 .active {
border:1px dashed red;
}
//通过class获取元素
function getClass(cls) {
var ret = [];
var els = document.getElementsByTagName("*");
for (var i = 0; i < els.length; i++) {
//判断els[i]中是否存在cls这个className;.indexOf("cls")判断cls存在的下标,如果下标>=0则存在;
if (els[i].className === cls || els[i].className.indexOf("cls") >= 0 || els[i].className.indexOf(" cls") >= 0 || els[i].className.indexOf(" cls ") > 0) {
ret.push(els[i]);
}
}
return ret;
}
function getStyle(obj, attr) { //解决JS兼容问题获取正确的属性值
return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj, false)[attr];
}
function startMove(obj, json, fun) {
clearInterval(obj.timer);
obj.timer = setInterval(function() {
var isStop = true;
for (var attr in json) {
var iCur = 0;
//判断运动的是不是透明度值
if (attr == "opacity") {
iCur = parseInt(parseFloat(getStyle(obj, attr)) * 100);
} else {
iCur = parseInt(getStyle(obj, attr));
}
var ispeed = (json[attr] - iCur) / 8;
//运动速度如果大于0则向下取整,如果小于0想上取整;
ispeed = ispeed > 0 ? Math.ceil(ispeed) : Math.floor(ispeed);
//判断所有运动是否全部完成
if (iCur != json[attr]) {
isStop = false;
}
//运动开始
if (attr == "opacity") {
obj.style.filter = "alpha:(opacity:" + (json[attr] + ispeed) + ")";
obj.style.opacity = (json[attr] + ispeed) / 100;
} else {
obj.style[attr] = iCur + ispeed + "px";
}
}
//判断是否全部完成
if (isStop) {
clearInterval(obj.timer);
if (fun) {
fun();
}
}
}, 30);
}
总结
到此这篇基于js实现的图片拖拽排序源码的文章就介绍到这了,更多相关js图片拖拽排序内容请搜索考高分网以前的文章或继续浏览下面的相关文章希望大家以后多多支持考高分网!



