jQuery实现的选择商品飞入文本框动画效果完整实例


Posted in Javascript onAugust 10, 2016

本文实例讲述了jQuery实现的选择商品飞入文本框动画效果。分享给大家供大家参考,具体如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title></title>
  <script src="jquery-1.7.2.min.js" type="text/javascript"></script>
  <script>
    $(function() {
      initProListClick();
    });
    function initProListClick() {
      var brandUlObj = $('#brandListForOperate li');
      brandUlObj.unbind('click').on('click', function () {
        var thisLiObj = $(this);
        //获取商品的值和名称
        var thisProValue = thisLiObj.find('input').val(),
          thisProName = thisLiObj.find('.brand-text').text();
        //调用动画效果方法
        moveProEffect(thisLiObj, thisProValue, thisProName);
        brandUlObj.find('input').attr({ 'checked': false });
        brandUlObj.not(thisLiObj).removeClass('brand-selected');
        if (thisLiObj.hasClass('brand-selected')) {
          thisLiObj.find('input').attr({ 'checked': true });
          // thisLiObj.removeClass('brand-selected');
          // thisLiObj.find('input').attr({'checked':false});
        } else {
          thisLiObj.addClass('brand-selected');
          thisLiObj.find('input').attr({ 'checked': true });
        }
      });
    }
    //定义选择商品一共飞入的效果
    function moveProEffect(obj, brandVal, brandName) {
      //获取每一个LI标签的left top距离
      var divTop = $(obj).offset().top;
      var divLeft = $(obj).offset().left;
      //定义移动效果的div,并将点击的LI中的html内容放入此div中
      var thisEffectObj = $('#proEffectPanel');
      thisEffectObj.html(obj.html()).find('input').attr({ "checked": true });
      //初始化定义移动效果的div样式
      $(thisEffectObj).css({ "position": "static", "display": "none", "z-index": "auto", "left": "auto", "top": "auto", "opacity": "1", "border-radius": "0px" });
      //移动过程中div的样式
      $(thisEffectObj).css({ "position": "absolute", "display": "block", "z-index": "500", "left": divLeft + "px", "top": divTop + "px", "border-radius": "4px" });
      $(thisEffectObj).animate({
        "left": ($("#txtProName").offset().left - $("#txtProName").width()+165) + "px",
        "top": ($(document).scrollTop()) + "px",
        "width": "190px",
        "height": "30px"
      }, 500, function () {
        $(thisEffectObj).animate({
          "left": ($("#txtProName").offset().left -7) + "px",
          "top": ($("#txtProName").offset().top-5) + "px"
        }, 500, function () {
          $('#txtProName').val(brandName);
        }).fadeTo(0, 0.1).hide(0);
      });
    }
  </script>
</head>
<body>
  <style>
    html,body{font-size: 12px;color: #696969;font-family: 'Microsoft YaHei';}
    .txt-main { height: 30px; line-height: 30px; border: 1px solid #c3c3c3; border-radius: 4px; padding: 0 4px; width: 180px; background: #fff url(image/form/form-input-txt-bg.png) repeat-x; }
    .txt-main:focus { color: #2a6894; border-color: #66afe9; outline: 0; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); }
    .pro-list-panel{ width: 330px;overflow: hidden;border: 1px solid #f3f3f3;padding-bottom: 10px;float: left;margin-left: 10px;}
    .pro-list-main{list-style-type: none;overflow: hidden;padding: 0;margin: 0;}
    .pro-list-main li, #proEffectPanel { border: 1px solid #95b8e7; width: 147px; overflow: hidden; float: left; margin-left: 5px; margin-top: 5px; height: 30px; line-height: 30px; }
    .pro-list-main li div, #proEffectPanel div { float: left; height: 30px; line-height: 30px; }
    .pro-list-main li div.brand-chk, #proEffectPanel div.brand-chk { width: 12px; padding: 5px 6px 0 5px; }
    .pro-list-main li div.brand-text, #proEffectPanel div.brand-text { width: 124px; }
    .pro-list-main li:hover, .pro-list-main li.brand-selected, #proEffectPanel { background-color: #ceebf4; }
  </style>
  <div class="pro-list-panel">
    <h2> 选择你的商品:</h2>
    <ul class="pro-list-main" id="brandListForOperate">
      <li title="康师傅">
        <div class="brand-chk"><input type="checkbox" id="Checkbox1" value="1" /></div>
        <div class="brand-text">康师傅</div>
      </li>
      <li title="鸿星尔克">
        <div class="brand-chk"><input type="checkbox" id="Checkbox2" value="2" /></div>
        <div class="brand-text">鸿星尔克</div>
      </li>
      <li title="程辉">
        <div class="brand-chk"><input type="checkbox" id="Checkbox3" value="2" /></div>
        <div class="brand-text">程辉</div>
      </li>
      <li title="士力架">
        <div class="brand-chk"><input type="checkbox" id="Checkbox4" value="2" /></div>
        <div class="brand-text">士力架</div>
      </li>
      <li title="三笑">
        <div class="brand-chk"><input type="checkbox" id="Checkbox5" value="2" /></div>
        <div class="brand-text">三笑</div>
      </li>
      <li title="椰牛">
        <div class="brand-chk"><input type="checkbox" id="Checkbox6" value="2" /></div>
        <div class="brand-text">椰牛</div>
      </li>
      <li title="飞科">
        <div class="brand-chk"><input type="checkbox" id="Checkbox7" value="2" /></div>
        <div class="brand-text">飞科</div>
      </li>
    </ul>
    <div id="proEffectPanel" style="display: none;">
    </div>
  </div>
  <div class="pro-list-panel">
    <h2> 你选择的商品·:</h2>
      <input type="text" name="txtProName" value="" id="txtProName" class="txt-main" />
  </div>
</body>
</html>

运行效果截图如下:

jQuery实现的选择商品飞入文本框动画效果完整实例

希望本文所述对大家jQuery程序设计有所帮助。

Javascript 相关文章推荐
Extjs Gird 支持中文拼音排序实现代码
Apr 15 Javascript
js实现的复制兼容chrome和IE
Apr 03 Javascript
SuperSlide2实现图片滚动特效
Jun 20 Javascript
详解JavaScript中的blink()方法的使用
Jun 08 Javascript
jquery实现动画菜单的左右滚动、渐变及图形背景滚动等效果
Aug 25 Javascript
js对字符串进行编码的方法总结(推荐)
Nov 10 Javascript
在JS中a标签加入单击事件屏蔽href跳转页面
Dec 16 Javascript
AngularJs点击状态值改变背景色的实例
Dec 18 Javascript
react-redux中connect的装饰器用法@connect详解
Jan 13 Javascript
AnglarJs中的上拉加载实现代码
Feb 08 Javascript
Vue中的v-for循环key属性注意事项小结
Aug 12 Javascript
vue项目中使用vue-layer弹框插件的方法
Mar 11 Javascript
最棒的Angular2表格控件
Aug 10 #Javascript
浅谈js中的三种继承方式及其优缺点
Aug 10 #Javascript
jQuery+HTML5+CSS3制作支持响应式布局时间轴插件
Aug 10 #Javascript
基于js中的原型、继承的一些想法
Aug 10 #Javascript
新入门node.js必须要知道的概念(必看篇)
Aug 10 #Javascript
jQuery制作圣诞主题页面 更像是爱情影集
Aug 10 #Javascript
jquery实现拖动效果
Aug 10 #Javascript
You might like
php实现cc攻击防御和防止快速刷新页面示例
2014/02/13 PHP
PHP动态柱状图实现方法
2015/03/30 PHP
jquery提取元素里的纯文本不包含span等里的内容
2013/09/30 Javascript
js charAt的使用示例
2014/02/18 Javascript
node.js中使用socket.io的方法
2014/12/15 Javascript
jquery实现仿JqueryUi可拖动的DIV实例
2015/07/31 Javascript
js闭包用法实例详解
2016/12/13 Javascript
Easyui在treegrid添加控件的实现方法
2017/06/23 Javascript
JavaScript中常见的八个陷阱总结
2017/06/28 Javascript
JavaScript之DOM_动力节点Java学院整理
2017/07/03 Javascript
AngularJS模糊查询功能实现代码(过滤内容下拉菜单排序过滤敏感字符验证判断后添加表格信息)
2017/10/24 Javascript
vue+vuex+json-seiver实现数据展示+分页功能
2019/04/11 Javascript
vant中的toast轻提示实现代码
2020/11/04 Javascript
[06:25]第二届DOTA2亚洲邀请赛主赛事第二天比赛集锦.mp4
2017/04/03 DOTA
Python实现设置windows桌面壁纸代码分享
2015/03/28 Python
python删除指定类型(或非指定)的文件实例详解
2015/07/06 Python
Python 的类、继承和多态详解
2017/07/16 Python
pygame游戏之旅 添加游戏介绍
2018/11/20 Python
python实现dijkstra最短路由算法
2019/01/17 Python
django的聚合函数和aggregate、annotate方法使用详解
2019/07/23 Python
django商品分类及商品数据建模实例详解
2020/01/03 Python
python使用pandas抽样训练数据中某个类别实例
2020/02/28 Python
python实现磁盘日志清理的示例
2020/11/05 Python
德国在线香料制造商:Gewürzland
2020/03/10 全球购物
Crabtree & Evelyn欧盟:豪华洗浴、身体和护发
2021/03/09 全球购物
请说出几个常用的异常类
2013/01/08 面试题
What's the difference between Debug and Trace class? (Debug类与Trace类有什么区别)
2013/09/10 面试题
打造完美自荐信
2014/01/24 职场文书
师德个人剖析材料
2014/02/02 职场文书
家长写给孩子的评语
2014/04/18 职场文书
大学活动总结模板
2014/07/10 职场文书
纪检干部个人对照检查材料
2014/09/23 职场文书
党员剖析材料范文
2014/09/30 职场文书
2015年读书月活动总结
2015/03/26 职场文书
宾馆前台接待岗位职责
2015/04/02 职场文书
Python利用folium实现地图可视化
2021/05/23 Python