就是类似于google这个页面的顶部效果http://www.google.com/design/spec/resources/layout-templates.html
谢谢
我是用Jquery的scroll事件做出来的。为了给题主写例子,我定义了5个块。第一个块是头部,第二个块是下面的内容。头部又包含了三个小块,一个放左边的那个图标,一个放下面的Resource,一个放滚动鼠标后显示的内容ResourcesLayout > Templates。然后,主要代码是:
$(document).ready(function(){$(window).scroll(function(){var tmp=$(window).scrollTop();if(tmp>200){$('.d1').css('height','60px');$('.d1_3').text('ResourcesLayout > Templates');$('.d1_2').hide();}if(tmp==60){$('.d1').css('height','200px');$('.d1_3').text('');$('.d1_2').show();}if(tmp<200&&tmp>60){var tmph=200-tmp+'px';$('.d1').css('height',tmph);$('.d1_3').text('');$('.d1_2').show();}
})})
判断scrollTop的大小,与头部块的大小作比较。然后再动态改变头部块的高度。全部的代码在下面。你要用的话还得下载一个jquery.js的文件。
<!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><script type="text/javascript" src="../style/jQuery.js"></script><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style>.d1{position: fixed;top: 0px;left: 0px;height: 200px;width: 100%;background:#343434;overflow:hidden;z-index: 11;}.d1_1{position: absolute;left: 20px;top: 10px;width: auto;height: 40px;line-height: 40px;font-size: 18px;color: #fff;}.d1_2{position: absolute;left: 80px;bottom: 20px;font-size: 34px;color: #fff;}.d1_3{position: absolute;left: 80px;top: 10px;height: 40px;line-height: 40px;font-size: 18px;color: #fff;}.content{position: absolute;top: 220px;left: 0px;width: 100%;height: auto;
}</style><script>$(document).ready(function(){$(window).scroll(function(){var tmp=$(window).scrollTop();if(tmp>200){$('.d1').css('height','60px');$('.d1_3').text('ResourcesLayout > Templates');$('.d1_2').hide();}if(tmp==60){$('.d1').css('height','200px');$('.d1_3').text('');$('.d1_2').show();}if(tmp<200&&tmp>60){var tmph=200-tmp+'px';$('.d1').css('height',tmph);$('.d1_3').text('');$('.d1_2').show();}
})})</script></head>
<body><div class="d1"><div class="d1_1">
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(1)
我是用Jquery的scroll事件做出来的。
为了给题主写例子,我定义了5个块。第一个块是头部,第二个块是下面的内容。
头部又包含了三个小块,一个放左边的那个图标,一个放下面的Resource,一个放滚动鼠标后显示的内容ResourcesLayout > Templates。
然后,主要代码是:
$(document).ready(function(){
$(window).scroll(function(){
var tmp=$(window).scrollTop();
if(tmp>200){
$('.d1').css('height','60px');
$('.d1_3').text('ResourcesLayout > Templates');
$('.d1_2').hide();
}
if(tmp==60){
$('.d1').css('height','200px');
$('.d1_3').text('');
$('.d1_2').show();
}
if(tmp<200&&tmp>60){
var tmph=200-tmp+'px';
$('.d1').css('height',tmph);
$('.d1_3').text('');
$('.d1_2').show();
}
})
})
判断scrollTop的大小,与头部块的大小作比较。然后再动态改变头部块的高度。
全部的代码在下面。你要用的话还得下载一个jquery.js的文件。
<!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>
<script type="text/javascript" src="../style/jQuery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
.d1{
position: fixed;
top: 0px;
left: 0px;
height: 200px;
width: 100%;
background:#343434;
overflow:hidden;
z-index: 11;
}
.d1_1{
position: absolute;
left: 20px;
top: 10px;
width: auto;
height: 40px;
line-height: 40px;
font-size: 18px;
color: #fff;
}
.d1_2{
position: absolute;
left: 80px;
bottom: 20px;
font-size: 34px;
color: #fff;
}
.d1_3{
position: absolute;
left: 80px;
top: 10px;
height: 40px;
line-height: 40px;
font-size: 18px;
color: #fff;
}
.content{
position: absolute;
top: 220px;
left: 0px;
width: 100%;
height: auto;
}
</style>
<script>
$(document).ready(function(){
$(window).scroll(function(){
var tmp=$(window).scrollTop();
if(tmp>200){
$('.d1').css('height','60px');
$('.d1_3').text('ResourcesLayout > Templates');
$('.d1_2').hide();
}
if(tmp==60){
$('.d1').css('height','200px');
$('.d1_3').text('');
$('.d1_2').show();
}
if(tmp<200&&tmp>60){
var tmph=200-tmp+'px';
$('.d1').css('height',tmph);
$('.d1_3').text('');
$('.d1_2').show();
}
})
})
</script>
</head>
<body>
<div class="d1">
<div class="d1_1">