zoukankan      html  css  js  c++  java
  • JQuery实现的模块交换动画效果

    
    


    <!
    doctype html> <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>JQuery实现的模块交换动画效果</title> <meta name="Keywords" content="jquery,模块,交换,动画,javascript特效"/> <meta name="Description" content="JQuery实现的模块交换动画效果。在模块交换过程中,设置模块position为absolute,实现交换。"/> <script type="text/javascript" src="jquery-1.8.1.min.js""></script> <style type="text/css"> div.container{position:relative;} div.container .itemA,div.container .itemE{width:300px;height:100px;background:#aaa;} div.container .itemE{background:#eee;} div.container .itemA .btn,div.container .itemE .btn{text-align:right;} </style> <script type="text/javascript"> function addItem() { var p = $('.container'), lastChild = p.children(":last"); p.append(lastChild.clone().attr('class', lastChild.attr('class') == 'itemE' ? 'itemA' : 'itemE')); p.children(':last').append("--" + new Date().toLocaleTimeString()); } function setItemPosition(dvContainer, isAB) {//更新子项的position和top dvContainer.css('height', isAB ? dvContainer.height() : ''); var h = 0, eachItem; dvContainer.children().each(function () { eachItem = $(this); eachItem.css({ 'position': isAB ? 'absolute' : 'relative', 'top': isAB ? h : '' }); if (isAB) h += eachItem.outerHeight(true); }); } $(function () { $('#btnAdd').click(addItem); $('.btn input').live('click', function () { var o = $(this), pNode = o.parent().parent(), v = o.val(); switch (v) { case '删除': if (pNode.parent().children().length < 2) alert('至少留有一项!'); else pNode.remove(); break; case '': case '': var refNode = pNode[v == '' ? 'prev' : 'next'](); if (refNode[0] == null) { alert(v == '' ? '已经是第一位!' : '已经是最后一位!'); return false; } setItemPosition(pNode.parent(), true); var nItemTop = refNode.css('top'), refItemTop = pNode.css('top'); pNode[v == '' ? 'after' : 'before'](refNode); //交换位置 pNode.animate({ top: nItemTop }, 300); ; refNode.animate({ top: refItemTop }, 300, function () { setItemPosition(pNode.parent()); }); break; } }); }); </script> </head> <body> <input type="button" value="添加新快" id="btnAdd"/> <div class="container"> <div class="itemA"><div class="btn"><input type="button" value="删除" /><input type="button" value="上" /><input type="button" value="下" /></div>其他内容</div> <div class="itemE"><div class="btn"><input type="button" value="删除" /><input type="button" value="上" /><input type="button" value="下" /></div>其他内容</div> </div> </body> </html>
  • 相关阅读:
    session和cookie的理解
    CSS3媒体查询能检测到的特性小结
    怎样让搜索引擎收录你的网站|向搜索引擎提交你的网站
    vue-i18n vue-cli项目中实现国际化 多语言切换功能 一
    chrome中hack解决input:-webkit-autofill自定义样式
    知识分享
    iPhone的CSS3媒体查询
    C#中异常:“The type initializer to throw an exception(类型初始值设定项引发异常)”的简单分析与解决方法
    快速原型设计工具-Axure RP的介绍及简单使用(生产初期向客户展示设计产品的原型-也就是展示产品)
    纯CSS实现下拉菜单及下拉容器等(纯CSS实现导航条及导航下拉容器)
  • 原文地址:https://www.cnblogs.com/yzryc/p/6249382.html
Copyright © 2011-2022 走看看