html元素li移动动态效果
在日常工作当中遇到了一个问题,平铺型列表修改单个内容设置排序时列表排序应与之对应。一下是一个小小的例子;简单的解决了此类问题,以浮动的形式改变当前的数据的显示顺序。有不足之处欢迎指点,后期还会做一个更完善的版本。敬请期待!
效果预览:

代码实现:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
html, body, div, ul {margin: 0px;padding: 0px;}
.clear {clear: both;}
.content, .footer {margin: 0 auto;width: 90%;}
.content {border: solid 2px yellow;}
.footer {border: solid 2px red;}
.content ul li {float: left;width: 100px;height: 70px;margin: 5px 5px;border: solid 2px red;list-style-type: none;background-color: #ccc;}
</style>
<script src="js/jquery.js"></script>
<script type="text/javascript">
$(function () {
var m_nodeObj, t_nodeObj, tempWidth;
$("#btnSet").click(function () {
m_nodeObj = $(".content li:eq(" + $("#itemNumb").val() + ")");
t_nodeObj = $(".content li:eq(" + $("#setNumb").val() + ")"); ////方案一 无动画
//m_nodeObj.insertAfter(t_nodeObj); ////方案二
//$(m_nodeObj).animate({ "width": "toggle" }, function () {
// $(this).insertAfter($(t_nodeObj)).animate({ "width": "toggle" })
//}) //方案三
$(m_nodeObj).clone(true).appendTo(".content ul")
.css({ "position": "absolute", "top": node.ordinate(m_nodeObj), "left": node.abscissa(m_nodeObj) })
.animate({ width: node.width(m_nodeObj) + 10, height: node.height(m_nodeObj) + 10, top: node.ordinate(m_nodeObj) - 5, left: node.abscissa(m_nodeObj) - 5 }, 200, function () {
tempWidth = node.width(m_nodeObj);
t_nodeObj.animate({ "margin-right": tempWidth });
m_nodeObj.animate({ "width": '0px' }, function () { $(this).remove() });
})
.animate({ width: node.width(m_nodeObj), height: node.height(m_nodeObj), top: node.ordinate(t_nodeObj), left: node.abscissa(t_nodeObj) }, 500, function () {
// m_nodeObj.insertAfter(t_nodeObj).animate({ "width": tempWidth }); $(this).remove();
t_nodeObj.css({ "margin-right": "0px" });
m_nodeObj.css("width", tempWidth).insertAfter(t_nodeObj);
$(this).remove(); })
})
})
node = {
abscissa: function (obj) {
return obj.offset().left - parseInt(obj.css("margin-left").replace("px", ""));
},
ordinate: function (obj) {
return obj.offset().top - parseInt(obj.css("margin-top").replace("px", ""));
},
height: function (obj) {
return parseInt(obj.css("height").replace("px", ""));
},
width: function (obj) {
return parseInt(obj.css("width").replace("px", ""));
}
} </script>
</head>
<body>
<div class="content">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
</ul>
<div class="clear"></div>
</div>
<div class="footer">
<br />
元素: <input type="text" id="itemNumb" />
<br />
<br />
目的: <input type="text" id="setNumb" />
<br />
<br />
<input type="button" value="设置" id="btnSet" />
</div>
</body>
</html>
html元素li移动动态效果的更多相关文章
- 关于table的td和ul元素li隔行变色的功能实现
table元素的td和ul元素li隔行变色的功能实现 利用css控制二者的样式轻松实现隔行换色: 例如:table的css样式控制: table tr td{ background-color:颜 ...
- 横向子菜单栏ul根据其子元素li个数动态获取宽度,并与父li绝对垂直居中的jquery代码段
;(function(window){ $('.menuitem').hover(function(){ $('>a',this).css('background-color ...
- 关于li元素嵌套的事儿
今天阅读<锋利的jQuery>第二版2.6节案例研究部分的时候,遇到一个问题. <ul> <li class="a1"><a href=& ...
- ul或者ol中添加li元素
<!doctype html><html> <head> <meta charset="utf-8"> ...
- CCS设置第一个li的元素与其他li样式不同
<div class="ly-content-list"> <ul> <li> <div class="title"& ...
- AngularJS的基础元素应用
<!doctype html> <!-- 标记ng-app告诉AngularJS处理整个HTML页并引导应用 --> <html ng-app> <head& ...
- <<< Jquery查找元素、选择器使用方法总结
$("#myDiv"); //根据给定的ID匹配一个元素,用于搜索id 属性中给定的值,id属性必须是唯一的 $("div"); //根据给定的元素名匹配所有元 ...
- VB下对HTML元素的操作
<!DOCTYPE html> <html> <head> <title>test</title> </head> <bo ...
- 在js中怎么样选择互斥的相邻元素
在使用jquery中,我们通常会选择siblings()去选择相邻元素,使用eq()方法去匹配元素,使用index()获取对应元素的索引值,具体jquery代码如下: <style> *{ ...
随机推荐
- cc2530 timer 3 PWM <可调占空比>
前提: 开始用的是 cc2530 timer 1来做PWM的,已经可调占空比了,但是由于硬件的改动,需要用timer 3 和 timer 4 代替.由于调试过程中出了些小问题,于是自己把这个贴出来.关 ...
- HDU 5481 Desiderium 动态规划
Desiderium Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=548 ...
- 【机器学习算法-python实现】svm支持向量机(1)—理论知识介绍
(转载请注明出处:http://blog.csdn.net/buptgshengod) 1.背景 强烈推荐阅读(http://www.cnblogs.com/jerrylead/archiv ...
- Linux dd——备份命令
Linux学习笔记之备份命令dd 功能:把指定的输入文件拷贝到指定的输出文件中,并且在拷贝过程中可以进行格式转换.可以用该命令实现DOS下的diskcopy命令的作用.先用dd命令把软盘上的数据写成硬 ...
- linux cpio 备份命令
cpio 命令 [root@linux ~]# cpio -covB > [file|device] <==备份[root@linux ~]# cpio -icduv < [fi ...
- 如何定位到div滚动条的最底端
function ScrollDiv() { var ex = document.getElementById("calm"); ex.scrollTop = ex.scrollH ...
- Java基础知识强化之多线程笔记05:Java程序运行原理 和 JVM的启动是多线程的吗
1. Java程序运行原理: Java 命令会启动Java 虚拟机,启动 JVM,等于启动了一个应用程序,也就是启动了一个进程.该进程会自动启动一个 “主线程” ,然后主线程去调用某个类的 m ...
- Java设计模式07:常用设计模式之装饰器模式(结构型模式)
1. Java之装饰器模式(Decorator Pattern) (1)概述: 装饰模式在Java种使用也很广泛,比如我们在重新定义按钮.对话框等时候,实际上已经在使用装饰模式了.在不必改变原 ...
- 分享一个字数限制和统计的UITextView分类方法
- (NSUInteger)letterCountWithLimits:(NSInteger)limits { NSString *toBeString = self.text; NSUInteger ...
- JAVA_eclipse 保留Java文件时自动格式化代码和优化Import
Eclipse 保存Java文件时自动格式化代码和优化Import Eclipse中format代码的快捷方式是ctrl+shift+F,如果大家想保存 java文件的时候 自动就格式化代码+消除不必 ...