zoukankan      html  css  js  c++  java
  • [JQuery代码]超酷鼠标滑过背景高亮效果

    1、效果及功能说明 

    鼠标滑过悬停特效,div css制作产品列表图片布局通过鼠标滑过产品图片背景高亮闪烁显示,产品标题滑动显示或隐藏 

    2、实现原理 

    首先定义好一个重复实现效果的方法,然后定义光带出现速度和从什么位置出现,在定义当鼠标触及到图片后标题出什么位置出现到什么为位置停止,中间要花多少时间,最后在定义当鼠标离开图片后标题缩回去到那里和用的时间 

    主要的方法 

    $(this).find(".shine").css("background-position","-160px 0");
    //定义重复的动画效果
    
    $(this).find(".shine").animate({backgroundPosition: '160px 0'},500);
    //定义光带的动画效果和用时
    
    $(this).find(".title").stop().animate({left:'0px'},{queue:false,duration:450});
    //鼠标触及后的标图出现的到那里停止和用时
    
    $(this).find(".title").stop().animate({left:'-160px'},{queue:false,duration:200})
    //鼠标离开后标题的回缩到哪里和用时

    3、效果图 
     

    4、运行环境 
    IE6 IE7 IE8及以上 Firefox 和 Google Chrome游览器下都可实现 
    5、所有图片的压缩包新建一个文件后将包解压放进文件夹图片的压缩包在页面的最下方可以看到并下载下载后无需修改文件夹名因为本身就已经写好了和html5内的路径相吻合 
    6、将创建html文件保存的时候将编码类型换成(UTF-8有签名)这样可以让部分中文正常的显示出来,将保存类型(T)换成(所有文件(*.*)),将html5和解压后的图片文件夹放在同一个文件夹内效果 
    7、代码

    <!DOCTYPE html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    </head>
    
    <body>
    
    <style type="text/css">
    *{margin:0;padding:0;list-style-type:none;}
    a,img{border:0;text-decoration:none;}
    body{font:12px/180% Arial, Helvetica, sans-serif, "新宋体";}
    /* brands-list */
    .brands-list{width:480px;height:460px;overflow:hidden;margin:20px auto 0 auto;}
    .brands-list li{float:left;width:155px;margin:0 4px 7px 0;display:inline;}
    .brands-list li a{position:relative;height:104px;display:block;overflow:hidden;cursor:pointer;}
    .brands-list li a .title{z-index:2;position:absolute;bottom:10px;left:-160px;width:150px;height:20px;padding:0 0 0 10px;color:#f1e8eb;line-height:17px;background:url(images/img_caption_bg.png) no-repeat;}
    .brands-list li a .shine{z-index:3;position:absolute;top:0;left:0;width:160px;height:104px;background:url(images/shine_brands.png) no-repeat -160px 0;}
    
    .brands-list li a .title{_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='images/img_caption_bg.png');}
    .brands-list li a .shine{_background:none;}
    </style>
    
    <div class="brands-list">
        <ul>
            <li><a href="http://www.17sucai.com/"><img src="images/01.jpg" alt="Prada"/><span class="title">Prada</span><span class="shine">&nbsp;</span></a></li>
            <li><a href="http://www.17sucai.com/"><img src="images/02.jpg" alt="Dolce&#038;Gabbana"/><span class="title">Dolce&#038;Gabbana</span><span class="shine">&nbsp;</span></a></li>
            <li><a href="http://www.17sucai.com/"><img src="images/03.jpg" alt="Etro"/><span class="title">Etro</span><span class="shine">&nbsp;</span></a></li>
            <li><a href="http://www.17sucai.com/"><img src="images/04.jpg" alt="Fendi"/><span class="title">Fendi</span><span class="shine">&nbsp;</span></a></li>
            <li><a href="http://www.17sucai.com/"><img src="images/05.jpg" alt="Michael Kors"/><span class="title">Michael Kors</span><span class="shine">&nbsp;</span></a></li>
            <li><a href="http://www.17sucai.com/"><img src="images/06.jpg" alt="Neil Barrett"/><span class="title">Neil Barrett</span><span class="shine">&nbsp;</span></a></li>
            <li><a href="http://www.17sucai.com/"><img src="images/07.jpg" alt="Moncler"/><span class="title">Moncler</span><span class="shine">&nbsp;</span></a></li>
            <li><a href="http://www.17sucai.com/"><img src="images/09.jpg" alt="Parosh"/><span class="title">Parosh</span><span class="shine">&nbsp;</span></a></li>
            <li><a href="http://www.17sucai.com/"><img src="images/04.jpg" alt="Fendi"/><span class="title">Fendi</span><span class="shine">&nbsp;</span></a></li>
        </ul>
    </div><!--brands-list end-->
    
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    //定义个可以激活所有函数的方法
        $(".brands-list li a").hover(function(){
        //定义一个鼠标触及到图片上的伪类方法
            $(this).find(".shine").stop();
            //定义一个遍历来停止当前所有的动画的方法
            $(this).find(".shine").css("background-position","-160px 0");
            //定义一个遍历来定义,标题和光带重复出现-160px开始出现
            $(this).find(".shine").animate({backgroundPosition: '160px 0'},500);
            //定义一个遍历来定义,一条光带出现扫过鼠标触及的图片光带动画为0.5秒        
                            $(this).find(".title").stop().animate({left:'0px'},{queue:false,duration:450});
    //定义一个遍历获得停止当前动画方法后在定义一个动画让标题最后停在距左0的位置标题单独动画的时间
        },function(){
            $(this).find(".title").stop().animate({left:'-160px'},{queue:false,duration:200});
            //定义一个遍历获得停止当前动画方法后在定义一个动画标题回到 -160的地方就是不见了标题回收的动画及时间
        });
    });
    </script>
    </body>
    </html>
  • 相关阅读:
    [FAQ] GitHub 开启二次验证之后,如何通过 https clone 项目 ?
    [FAQ] GoLand 需要手动开启代码补全吗 ?
    [FAQ] 夏玉米 按规则查询域名靠谱吗 ?
    [FAQ] Error: com.mysql.jdbc.Driver not loaded. :jdbc_driver_library
    [php-src] Php内核的有趣高频宏
    [php-src] Php扩展开发的琐碎注意点、细节
    [ELK] Docker 运行 Elastic Stack 支持 TLS 的两种简单方式
    [Contract] Solidity 生成随机数方案
    [MySQL] 导入数据库和表的两种方式
    [ELK] 生产环境中 Elasticsearch 的重要配置项
  • 原文地址:https://www.cnblogs.com/ranran/p/jquery_mouse_over_bg.html
Copyright © 2011-2022 走看看