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

效果预览:

代码实现:

 <!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移动动态效果的更多相关文章

  1. 关于table的td和ul元素li隔行变色的功能实现

    table元素的td和ul元素li隔行变色的功能实现 利用css控制二者的样式轻松实现隔行换色: 例如:table的css样式控制: table tr td{   background-color:颜 ...

  2. 横向子菜单栏ul根据其子元素li个数动态获取宽度,并与父li绝对垂直居中的jquery代码段

    ;(function(window){    $('.menuitem').hover(function(){        $('>a',this).css('background-color ...

  3. 关于li元素嵌套的事儿

    今天阅读<锋利的jQuery>第二版2.6节案例研究部分的时候,遇到一个问题. <ul> <li class="a1"><a href=& ...

  4. ul或者ol中添加li元素

    <!doctype html><html>    <head>        <meta charset="utf-8">      ...

  5. CCS设置第一个li的元素与其他li样式不同

    <div class="ly-content-list"> <ul> <li> <div class="title"& ...

  6. AngularJS的基础元素应用

    <!doctype html> <!-- 标记ng-app告诉AngularJS处理整个HTML页并引导应用 --> <html ng-app> <head& ...

  7. <<< Jquery查找元素、选择器使用方法总结

    $("#myDiv"); //根据给定的ID匹配一个元素,用于搜索id 属性中给定的值,id属性必须是唯一的 $("div"); //根据给定的元素名匹配所有元 ...

  8. VB下对HTML元素的操作

    <!DOCTYPE html> <html> <head> <title>test</title> </head> <bo ...

  9. 在js中怎么样选择互斥的相邻元素

    在使用jquery中,我们通常会选择siblings()去选择相邻元素,使用eq()方法去匹配元素,使用index()获取对应元素的索引值,具体jquery代码如下: <style> *{ ...

随机推荐

  1. URAL 1019 - Line Painting

    跟前面某个题一样,都是区间染色问题,还是用我的老方法,区间离散化+二分区间端点+区间处理做的,时间跑的还挺短 坑爹的情况就是最左端是0,最右端是1e9,区间求的是开区间 #include <st ...

  2. 【原创】OllyDBG 入门系列(一)-认识OllyDBG

     ****** http://blog.fishc.com/645.html   标 题: [原创]OllyDBG 入门系列(一)-认识OllyDBG作 者: CCDebuger时 间: 2006-0 ...

  3. .NET连接MySQL数据库的方法实现

    突然对.NET连接MySQL数据库有点兴趣,于是乎网上到处找资料,学习MySQL的安装,MySQL的使用等等等等,终于搞定了! 最终效果就是显示数据库中数据表的数据: 首先,当然要有MySQL数据库啦 ...

  4. 2014-2015 ACM-ICPC, Asia Xian Regional Contest G The Problem to Slow Down You 回文树

    The Problem to Slow Down You Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjud ...

  5. IOS开发-加载本地音乐

    IOS开发-加载本地音乐 $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text() ...

  6. 重现PHP Core的调用栈

        以前, 我曾经介绍过如何通过PHP的Core文件获取信息:如何调试PHP的Core之获取基本信息, 对于调用参数这块, 当时介绍的获取方法比较复杂. 于是今天我为PHP 5.4的.gdbini ...

  7. java_spring_依赖注入

    IOC反转控制 PersonService属性 PersonDao personDao接受通过xml注入的对象 PersonDaoBean.  Person中save()调用 PersonDaoBea ...

  8. Apache的rewrite规则详细介绍

    Apache的rewrite规则详细介绍 发布日期:2008-09-02 16:16 来源: 作者: 点击:7044 rewrite标志 R[=code](force redirect) 强制外部重定 ...

  9. How to Analyze Java Thread Dumps--reference

    原文地址:http://architects.dzone.com/articles/how-analyze-java-thread-dumps The Performance Zone is pres ...

  10. iOS 开发中你是否遇到这些经验问题(一)

    前言 小伙伴们在开发中难免会遇到问题, 你是如何解决问题的?不妨也分享给大家!如果此文章其中的任何一条问题对大家有帮助,那么它的存在是有意义的! 反正不管怎样遇到问题就要去解决问题, 在解决问题的同时 ...