您的位置:首页 > Web前端 > JQuery

jquery实现鼠标移入移除背景图片切换

2014-12-06 14:51 656 查看


<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jquery.js" mce_src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#sub").css("left",$("#super").offset().left);
$("#sub").css("top", $("#super").offset().top);

$("#super").css("background-image","url(banner1.jpg)");
$("#sub").css("background-image","url(banner2.jpg)");
$('#sub').css('opacity', 0);

$("#sub").hover(
function() {
$("#super").stop().animate({opacity: '0'},500);
$("#sub").stop().animate({opacity: '1'},500);
},
function() {
$("#sub").stop().animate({opacity: '0'},500);
$("#super").stop().animate({opacity: '1'},500);
});
}
);
</script>
<style>
*{margin:0;padding:0;}
#super{
width:1440px;
height:100px;
position:relative;
margin:auto;
}
#sub {
width:1440px;
height:100px;
position:absolute;
margin:auto;
}
</style>
</head>

<body>
<div id="super"></div>
<div id="sub"></div>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: