zoukankan      html  css  js  c++  java
  • 边框逐渐显示效果

    公司最近有一个商城的项目,需要这效果,本来想偷懒在网上找一下有没有插件什么的用一下,然后没找到,好吧,只有靠自己想了。

    我的想法是在一个div中放4个div,然后将里面的4个div用position属性放在外面div的上左下右四个位置,然后用jquery的animate的方法,当鼠标移动到最外面的div上时4个位置的div按照顺序呢显示出来。当鼠标移出时,再根据鼠标在div上停留的时间来确定从哪一个位置开始反向执行动画。具体代码如下:

    <!DOCTYPE html>
    <html>
    <head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
    *{
    margin:0;
    padding:0;
    }
    .main{200px;height:200px;margin:100px auto;position: relative}
    .div{
    position: absolute;
    background-color: #000000;
    }
    .top{
    top: 0;
    left: 0;
    height: 2px;
    0;
    }
    .right{
    right: 0;
    top: 2px;
    2px;
    height: 0;
    }
    .bottom{
    bottom: 0;
    right: 2px;
    0;
    height: 2px;
    }
    .left{
    left: 0;
    bottom: 2px;
    2px;
    height: 0;
    }
    </style>
    </head>
    <body>
    <div class="main">
    <div class="top div"></div>
    <div class="right div"></div>
    <div class="bottom div"></div>
    <div class="left div"></div>
    </div>
    <script src="jquery-1.7.2.min.js"></script>
    <script>
    var time=1000;
    var hoverTime=0;
    $(".main").hover(function(){
    $(".div").stop();
    hoverTime=new Date();
    $(".top").animate({
    "200px"
    },time,function(){
    $(".right").animate({
    height:"198px"
    },time,function(){
    $(".bottom").animate({
    "198px"
    },time,function(){
    $(".left").animate({
    height:"196px"
    },time)
    })
    })
    })
    },function(){
    var nowTime=new Date();
    var howLong=nowTime.getTime()-hoverTime.getTime();
    console.log(howLong)
    if(howLong>3000){
    $(".div").stop();
    $(".left").animate({
    height:0
    },time,function(){
    $(".bottom").animate({
    0
    },time,function(){
    $(".right").animate({
    height:0
    },time,function(){
    $(".top").animate({
    0
    },time)
    })
    })
    })
    }else if(howLong<=3000&&howLong>2000){
    $(".div").stop();
    $(".bottom").animate({
    0
    },time,function(){
    $(".right").animate({
    height:0
    },time,function(){
    $(".top").animate({
    0
    },time)
    })
    })
    }else if(howLong>1000&&howLong<=2000){
    $(".div").stop();
    $(".right").animate({
    height:0
    },time,function(){
    $(".top").animate({
    0
    },time)
    })

    }else if(howLong>0&&howLong<=1000){
    $(".div").stop();
    $(".top").animate({
    0
    },time)
    }
    });

    </script>
    </body>
    </html>

    本人技术有限,希望又更好方法的人可以不吝指教一下:)

  • 相关阅读:
    COCOS学习笔记--单点触控
    [ExtJS5学习笔记]第九节 Extjs5的mvc与mvvm框架结构简单介绍
    STM32F103 TIM1输出PWM设置
    【转】Android--UI之ProgressBar--不错
    【传】玩转Android---UI篇---ImageButton(带图标的按钮)
    【转】Android--多线程之Handler--不错
    【转】MFC获取程序目录路径方法
    【转】蓝牙4.0BLE cc2540 usb-dongle的 SmartRF Packet Sniffer 抓取数据方法--不错
    【转】windows常用消息大全(系统消息、通告消息、用户消息)
    【转】VC的MFC中重绘函数的使用总结(整理)
  • 原文地址:https://www.cnblogs.com/zaxxm/p/5299214.html
Copyright © 2011-2022 走看看