javascript代码实例教程-jQuery实现的感应鼠标悬停图片色彩渐显效果

发布时间:2019-01-09 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-jQuery实现的感应鼠标悬停图片色彩渐显效果脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

jQuery实现的感应鼠标悬停图片色彩渐显效果。本文实例讲述了jquery实现的感应鼠标悬停图片色彩渐显效果。分享给大家供大家参考。具体实现方法如下:

代码如下:

<!DOCTYPE htML PubLIC "-//W3C//DTD XHTML 1.0 TransITional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html XMlns="https://www.w3.org/1999/xhtml">
<head>
<title>超个性的感应鼠标悬停图片色彩渐显效果</title>
<;meta http-equiv="content-type" content="text/html;charset=gb2312">
<!--把下面代码加到<head>与</head>之间-->
<style type="text/css">
ul.gallery {
&nbsp;   width: 750px; /*--Adjust width according to your scenario--*/
    list-style: none;
    margin: 0; padding: 0;
}
ul.gallery li {
    float: left;
    margin: 10px 0 10px 25px;
    padding: 0;
    text-align: center;
    border: 1px solid #ccc;
    -moz-border-radius: 3px; /*--CSS3 Rounded Corners--*/
    -khtml-border-radius: 3px; /*--CSS3 Rounded Corners--*/
    -webkit-border-radius: 3px; /*--CSS3 Rounded Corners--*/
    display: inline; /*--Gimp Fix aka IE6 Fix - Fixes double margin bug--*/
}
ul.gallery li a.thumb {
    width: 336px; /*--Width of image--*/
    height: 240px; /*--Height of image--*/
    border-bottom: 1px solid #ccc;
    cursor: pointer;
}
ul.gallery li span { /*--Used to crop image--*/
    width: 336px;
    height: 240px;
    overflow: hidden;
    display: block;
}
ul.gallery li a.thumb:hover {
    background: #333; /*--Hover effect for browser with js turned off--*/
}
ul.gallery li h2 {
    font-weight: normal;
    margin: 0;
    padding: 10px;
    background: #f0f0f0;
    border-top: 1px solid #fff; /*--SuBTle bevel effect--*/
}
ul.gallery li a {
     text-decoration: none;
     color: #777;
     display: block;
     font-Size: 140%;
}
</style>
<script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $("ul.gallery li").hover(function() { //On hover...
        VAR thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'
        //Set a background image(thumbOver) on the <a> tag - Set position to bottom
        $(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});
        //AniMATE the image to 0 opacity (fade it out)
        $(this).find("span").stop().fadeTo('normal', 0 , function() {
            $(this).hide() //Hide the image after fade
        });
    } , function() { //on hover out...
        //Fade the image to full opacity
        $(this).find("span").stop().fadeTo('normal', 1).show();
    });
});
</script>
</head>
<body>
预览效果时左下角会提示错误,而且看不到效果,刷新一下就可以看到效果了;当然,在实际使用中,不会出现这样的问题。<br>
<!--把下面代码加到<body>与</body>之间-->
<ul class="gallery">
 <li>
  <a href="#" class="thumb"><span><img src="/html/txdm_2/images/20100904/336240.jpg" alt=""></span></a>
  <h2><a href="#">Sunflowa Media</a></h2>
 </li>
</ul>
</body>
</html>

觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!

脚本宝典总结

以上是脚本宝典为你收集整理的javascript代码实例教程-jQuery实现的感应鼠标悬停图片色彩渐显效果全部内容,希望文章能够帮你解决javascript代码实例教程-jQuery实现的感应鼠标悬停图片色彩渐显效果所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。