手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >jQuery实现的感应鼠标悬停图片色彩渐显效果
jQuery实现的感应鼠标悬停图片色彩渐显效果
摘要:本文实例讲述了jQuery实现的感应鼠标悬停图片色彩渐显效果。分享给大家供大家参考。具体实现方法如下:复制代码代码如下:超个性的感应鼠标悬停...

本文实例讲述了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>

<meta http-equiv="content-type" content="text/html;charset=gb2312">

<>

<style type="text/css">

ul.gallery {

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="http://www.jb51.netjs/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>

<>

<ul>

<li>

<a href="#"><span><img src="http://www.jb51.nethtml/txdm_2/images/20100904/336240.jpg" alt=""></span></a>

<h2><a href="#">Sunflowa Media</a></h2>

</li>

</ul>

</body>

</html>

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

【jQuery实现的感应鼠标悬停图片色彩渐显效果】相关文章:

jQuery实现表格行上下移动和置顶效果

js实现精美的图片跟随鼠标效果实例

JavaScript实现鼠标点击后层展开效果的方法

js兼容火狐显示上传图片预览效果的方法

基于jQuery实现的无刷新表格分页实例

JavaScript实现广告的关闭与显示效果实例

Jquery实现动态切换图片的方法

jQuery结合ajax实现动态加载文本内容

JQuery分屏指示器图片轮换效果实例

javascript实现淡蓝色的鼠标拖动选择框实例

精品推荐
分类导航