点击不能跳转
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="css/index.css">
<link rel="stylesheet" href="css/base.css">
<link rel="stylesheet" href="css/animation.css">
</head>
<body>
<header class="header">
<div class="header__wrap">
<div class="header__logo">慕课手机</div>
<div class="header__nav">
<a href="#" class="header__nav-item header__nav__item_status_active">首页</a>
<!-- <a href="#" class="header__nav-item">首页</a> -->
<a href="#" class="header__nav-item">外观</a>
<a href="#" class="header__nav-item">配置</a>
<a href="#" class="header__nav-item">型号</a>
<a href="#" class="header__nav-item">说明</a>
<a href="#" class="header__nav-item header__nav-item_custom_button">立即购买</a>
</div>
</div>
</header>
<!-- 第一屏 -->
<div class="screen-1">
<h2 class="screen-1__heading"><b>慕课手机</b> 让你的生活更精彩</h2>
<div class="screen-1__phone"></div>
<div class="screen-1__shadow"></div>
</div>
<!-- 第二屏 -->
<div class="screen-2">
<h2 class="screen-2__heading">优美的设计,更令人着迷</h2>
<h3 class="screen-2__subheading">采用受欢迎的设计,让它更加出色。<br>
款式小巧、轻便手感更舒适。绚丽高清的显示屏,整个外观显得格外精致。</h3>
<div class="screen-2__phone">
<div class="screen-2__point screen-2__point_i_1">高清摄像</div>
<div class="screen-2__point screen-2__point_custom_right screen-2__point_i_2">超薄机身</div>
<div class="screen-2__point screen-2__point_custom_right screen-2__point_i_3">大屏显示</div>
</div>
</div>
<!-- 第三屏 -->
<div class="screen-3">
<div class="screen-3__wrap">
<h2 class="screen-3__heading">外形小巧,功能强大的手机</h2>
<h3 class="screen-3__subheading">采用受欢迎的设计,让它更加出色。<br>
款式小巧、轻便手感更舒适。绚丽高清的显示屏,整个外观显得格外精致。</h3>
<div class="screen-3__phone"></div>
<div class="screen-3__features">
<a href="#" class="screen-3__features_item">
<div class="screen-3__features_item_number">5.7</div>
<div class="screen-3__features_item_desc">英寸大屏</div>
</a>
<a href="#" class="screen-3__features_item">
<div class="screen-3__features_item_number">1200</div>
<div class="screen-3__features_item_desc">万像素</div>
</a>
<a href="#" class="screen-3__features_item">
<div class="screen-3__features_item_number">3D</div>
<div class="screen-3__features_item_desc">touch</div>
</a>
<a href="#" class="screen-3__features_item">
<div class="screen-3__features_item_number">A9</div>
<div class="screen-3__features_item_desc">处理器</div>
</a>
</div>
</div>
</div>
<!-- 第四屏 -->
<div class="screen-4">
<div class="screen-4__wrap">
<h2 class="screen-4__heading">丰富的手机型号</h2>
<h3 class="screen-4__subheading">找到适合你的手机</h3>
<div class="screen-4__type">
<a href="#" class="screen-4__type_item screen-4__type_item_i-1">
<div class="screen-4__type_item_color">慕课红</div>
<div class="screen-4__type_item_storage">32G/64G/128G</div>
</a>
<a href="#" class="screen-4__type_item screen-4__type_item_i-2">
<div class="screen-4__type_item_color">土豪金</div>
<div class="screen-4__type_item_storage">32G/64G/128G</div>
</a>
<a href="#" class="screen-4__type_item screen-4__type_item_i-3">
<div class="screen-4__type_item_color">太空灰</div>
<div class="screen-4__type_item_storage">32G/64G/128G</div>
</a>
<a href="#" class="screen-4__type_item screen-4__type_item_i-4">
<div class="screen-4__type_item_color">绅士黑</div>
<div class="screen-4__type_item_storage">32G/64G/128G</div>
</a>
</div>
</div>
</div>
<!-- 第五屏 -->
<div class="screen-5">
<div class="screen-5__heading">游戏、学习、拍照,有这一部就够了</div>
<div class="screen-5__subheading">看视频、拍摄高清视频与照片、视频聊天、通话相结合,一机多功能,让您生活更丰富精彩。</div>
<div class="screen-5__bg"></div>
</div>
<!-- 第六屏 -->
<div class="screen-6">
<a href="#" class="screen-6__buttn">立即购买</a>
</div>
<aside class="aside">
<a href="#" class="aside__item aside__item_active">首页</a>
<a href="#" class="aside__item">外观</a>
<a href="#" class="aside__item">配置</a>
<a href="#" class="aside__item">型号</a>
<a href="#" class="aside__item">说明</a>
</aside>
<footer class="footer">© 2016 imooc.com 京ICP备13046642号</footer>
<!-- <script src="js/test.js"></script> -->
<script src="js/index.js"></script>
</body>
</html>
/*
BEM 设计模式
模块(没有前缀,多个单词用-链接)
元素(元素在模块之后,可以有多个层级,用——链接)
修饰(某元素、或者某模块特别的状态,必须有一个状态名和状态值,只用一个—链接)
*/
.header{
background-color: #f7f7f7;
}
.header__wrap{
width: 1200px;
height: 80px;
position: relative;
margin: 0 auto;
}
.header__logo{
width: 150px;
height: 38px;
font-size: 20px;
color: #07111b;
text-indent: 50px;
background: url(../img/logo.png) left center no-repeat;
-webkit-background-size: 38px 38px;
background-size: 38px 38px;
line-height: 38px;
position: absolute;
top: 50%;
margin-top: -19px;
left: 20px;
}
.header__nav{
position: absolute;
right: 20px;
height: 38px;
top: 50%;
margin-top: -19px;
}
.header__nav-item{
color: #292f35;
font-size: 14px;
display: block;
height: 38px;
line-height: 38px;
text-align: center;
float: left;
margin-left: 40px;
position: relative;
}
.header__nav-item:hover{
color: #f01400;
}
.header__nav__item_status_active{
color: #f01400;
border-bottom: 1px solid #f01400;
}
.header__nav__item_status_active::after{
content: "";
display: block;
width: 100%;
height: 2px;
position: absolute;
left: 0;
bottom: 0;
background-color: #f01400;
}
.header__nav-item_custom_button{
background-color: #000;
color: #f4f4f5;
width: 90px;
height: 38px;
border-radius: 3px;
}
/*第一屏*/
.screen-1{
height: 800px;
background: url(../img/bg-screen-1.png) center no-repeat;
-webkit-background-size: cover;
background-size: cover;
position: relative;
overflow: hidden;
}
.screen-1__heading{
font-weight: normal;
font-size: 46px;
color: #4d555d;
text-align: center;
padding-top: 152px;
}
.screen-1__heading b{
color: #f01400;
font-size: 46px;
font-weight: normal;
}
.screen-1__phone{
width: 1375px;
height: 305px;
background: url(../img/screen-1-phone.png) center no-repeat;
position: absolute;
left: 50%;
margin-left: -687px;
bottom: 180px;
z-index: 2;
}
.screen-1__shadow{
width: 1233px;
height: 411px;
background: url(../img/screen-1-shadow.png) center no-repeat;
position: absolute;
left: 50%;
margin-left: -616px;
bottom: 10px;
z-index: 1;
opacity: .8;
}
/*第二屏*/
.screen-2{
height: 800px;
position: relative;
overflow: hidden;
}
.screen-2__heading{
font-weight: normal;
font-size: 46px;
color: #f01400;
text-align: center;
padding-top: 96px;
line-height: 46px;
}
.screen-2__subheading{
font-size: 14px;
color: #2c3137;
text-align: center;
padding-top: 25px;
line-height: 28px;
}
.screen-2__phone{
width: 928px;
height: 873px;
background: url(../img/screen-2-phone.png) center no-repeat;
position: absolute;
left: 50%;
margin-left: -464px;
bottom: -345px;
z-index: 2;
}
.screen-2__point{
width: 108px;
padding-right: 112px;
height: 22px;
font-size: 22px;
line-height: 22px;
color: #4d555d;
background: url(../img/icon-point-right.png) no-repeat center right;
position: absolute;
}
.screen-2__point_custom_right{
padding: 0 0 0 112px;
background: url(../img/icon-point-left.png) no-repeat center left;
}
.screen-2__point_i_1{
top: 150px;
left: -130px;
}
.screen-2__point_i_2{
top: 30px;
right:130px;
}
.screen-2__point_i_3{
top: 330px;
right: 10px;
}
/*第三屏*/
.screen-3{
height: 800px;
position: relative;
background: url(../img/bg-screen-3.png) no-repeat;
-webkit-background-size: cover;
background-size: cover;
overflow: hidden;
}
.screen-3__wrap{
width: 1200px;
height: auto;
margin: 0 auto;
position: relative;
}
.screen-3__heading{
font-size: 46px;
line-height: 46px;
color: #fff;
text-align: left;
padding-top: 94px;
}
.screen-3__subheading{
font-size: 14px;
color: #fff;
text-align: left;
padding-top: 25px;
line-height: 28px;
}
.screen-3__phone{
width: 750px;
height: 875px;
background: url(../img/screen-3-phone.png) center top no-repeat;
position: absolute;
right: 0;
top: 195px;
bottom: 0px;
z-index: 2;
}
.screen-3__features{
position: absolute;
top: 395px;
left: 0;
width: 320px;
height: 280px;
}
.screen-3__features_item{
width: 128px;
height: 118px;
border: 1px solid #cd7173;
border-radius: 3px;
margin: 0 20px 20px 0;
float: left;
color: #fff;
text-align: center;
display: block;
}
.screen-3__features_item:hover{
box-shadow: 0 0 10px rgba(0,0,0,.5);
transition: all .5s;
}
.screen-3__features_item_number{
height: 36px;
line-height: 36px;
font-size: 36px;
padding: 28px 0 8px 0;
}
.screen-3__features_item_desc{
height: 14px;
line-height: 14px;
font-size: 14px;
}
/*第四屏*/
.screen-4{
height: 800px;
position: relative;
background: #fff;
overflow: hidden;
}
.screen-4__wrap{
width: 1200px;
height: auto;
margin: 0 auto;
position: relative;
}
.screen-4__heading{
font-size: 46px;
line-height: 46px;
color: #f01400;
text-align: center;
padding-top: 135px;
}
.screen-4__subheading{
font-size: 14px;
color: #464a4f;
text-align: center;
padding-top: 29px;
line-height: 28px;
}
.screen-4__type{
width: 1260px;
height: 270px;
position: absolute;
top: 304px;
margin-left: 30px;
}
.screen-4__type_item{
width: 220px;
height: 270px;
margin-right: 90px;
float: left;
position: relative;
text-align: center;
display: block;
}
.screen-4__type_item_i-1{
background: url(../img/phone-1.png);
}
.screen-4__type_item_i-2{
background: url(../img/phone-2.png);
}
.screen-4__type_item_i-3{
background: url(../img/phone-3.png);
}
.screen-4__type_item_i-4{
background: url(../img/phone-4.png);
}
.screen-4__type_item_color{
width: 100%;
height: 14px;
line-height: 14px;
font-size: 14px;
color: #2c3238;
position: absolute;
bottom: -44px;
}
.screen-4__type_item_storage{
width: 100%;
height: 12px;
line-height: 12px;
font-size: 12px;
color: #a4a9ae;
position: absolute;
bottom: -66px;
}
/*第五屏*/
.screen-5{
height: 800px;
background: #d9dde1;
position: relative;
overflow: hidden;
}
.screen-5__bg{
width: 1920px;
height: 433px;
background: url(../img/bg-screen-5.png) bottom center no-repeat;
-webkit-background-size: contain;
background-size: contain;
position: absolute;
left: 50%;
margin-left: -960px;
bottom: -100px;
}
.screen-5__heading{
font-weight: normal;
font-size: 46px;
color: #f01400;
text-align: center;
padding-top: 96px;
line-height: 46px;
}
.screen-5__subheading{
font-size: 14px;
color: #2c3137;
text-align: center;
padding-top: 25px;
line-height: 28px;
}
/*第六屏*/
.screen-6{
height: 320px;
position: relative;
background: #2b333b url(../img/bg-screen-buy.png) center no-repeat;
}
.screen-6__buttn{
width: 240px;
height: 80px;
text-align: center;
line-height: 80px;
font-size: 24px;
display: block;
color: #fff;
background: #f01414;
position: absolute;
top: 50%;
left: 50%;
margin-top: -40px;
margin-left: -120px;
border-radius: 4px;
}
.screen-6__buttn:hover{
box-shadow: 0 0 10px rgba(255,255,255,.5);
transition: all .5s;
}
.footer{
height: 80px;
line-height: 80px;
text-align: center;
font-size: 12px;
color: #fff;
background-color: #07111b;
}
.aside{
position: fixed;
padding: 5px 10px;
right: 0;
top: 50%;
margin-top: -100px;
background: #fff;
box-shadow: 0 0 10px rgba(0,0,0,.5);
z-index: 9;
}
.aside__item{
display: block;
width: 40px;
height: 30px;
border-bottom: 1px solid #edf1f2;
line-height: 30px;
padding: 5px 0;
font-size: 12px;
text-align: center;
}
.aside__item:hover{
color: #f01400;
}
.aside__item:last-child{
border-bottom: none;
}
.aside__item_active{
color: #f01400;
}
var getEle=function(selector){
return document.querySelector(selector);
}
var grtAllEle=function(selector){
return document.querySelectorAll(selector);
}
//获取元素样式
var getCls=function(element){
return element.getAttribute('class');
}
//设置元素样式
var setCls=function(element,cls){
return element.setAttribute('class',cls);
}
//为元素添加样式
var addCls=function(element,cls){
var baseCls=getCls(element);//获取默认类名
if(baseCls.indexOf(cls)===-1){
setCls(element,baseCls+' '+cls)
}
return
}
//为元素删除样式
var delCls=function(element,cls){
var baseCls=getCls(element);//获取默认类名
if(baseCls.indexOf(cls)!=-1){
setCls(element,baseCls.split(cls).join(' ').replace(/\s+/g,' '))
}
return
}
//第一步:初始化样式 init
var screenAnimateElements={
'.screen-1':[
'.screen-1__heading',
'.screen-1__phone',
'.screen-1__shadow',
],
'.screen-2':[
'.screen-2__heading',
'.screen-2__phone',
'.screen-2__subheading',
'.screen-2__point_i_1',
'.screen-2__point_i_2',
'.screen-2__point_i_3',
],
'.screen-3':[
'.screen-3__heading',
'.screen-3__phone',
'.screen-3__subheading',
'.screen-3__features',
],
'.screen-4':[
'.screen-4__subheading',
'.screen-4__heading',
'.screen-4__type_item_i-1',
'.screen-4__type_item_i-2',
'.screen-4__type_item_i-3',
'.screen-4__type_item_i-4',
],
'.screen-5':[
'.screen-5__subheading',
'.screen-5__heading',
'.screen-5__bg',
]
}
// 设置屏内元素为初始状态
var setScreenAnimateInit=function(screenCls){
var screen=document.querySelector(screenCls);//获取当前屏的元素
var animateElements=screenAnimateElements[screenCls];//需要设置的动画元素
for(var i=0;i<animateElements.length;i++){
var element=document.querySelector(animateElements[i]);
var baseCls=element.getAttribute('class');
element.setAttribute('class',baseCls+' '+animateElements[i].substr(1)+'_animate_init');
}
}
//设置播放屏内的元素动画
var playScreenAnimateDone=function(screenCls){
var screen=document.querySelector(screenCls);//获取当前屏的元素
var animateElements=screenAnimateElements[screenCls];//需要设置的动画元素
for(var i=0;i<animateElements.length;i++){
var element=document.querySelector(animateElements[i]);
var baseCls=element.getAttribute('class');
element.setAttribute('class',baseCls.replace('_animate_init','_animate_done'));
}
}
window.onload=function(){
for(k in screenAnimateElements){
setScreenAnimateInit(k);
}
}
// 第二部,滚动到那就播放到哪
window.onscroll=function(){
var top=document.body.scrollTop||document.documentElement.scrollTop;
if(top>80){
addCls(getEle('.header'),'header_status_back' );
addCls(getEle('.aside'),'aside_in');
}else{
delCls(getEle('.header'),'header_status_back' );
delCls(getEle('.aside'),'aside_in');
}
if(top>0){
playScreenAnimateDone('.screen-1');
}
if(top>800*1-200){
playScreenAnimateDone('.screen-2');
}
if(top>800*2-200){
playScreenAnimateDone('.screen-3');
}
if(top>800*3-200){
playScreenAnimateDone('.screen-4');
}
if(top>800*4-200){
playScreenAnimateDone('.screen-5');
}
}
var navItems=grtAllEle('.header__nav-item');
var setNavJump=function(i){
var item= navItems[i];
item.onclick=function(){
document.body.scrollTop = i*800;
document.documentElement.scrollTop = i*800;
console.log(i);
}
}
for(var i=0;i<navItems.length;i++){
setNavJump(i);
}
正在回答
同学你好,top只是一个变量,top=document.body.scrollTop是把页面的高度赋值给它,也就是说top的值就是一个数字。top=i*800只是给top这个变量重新赋值了而已。想要改变页面的滚动高度,还是需要直接操作document.body.scrollTop的哦。
如果我的回答帮助到了你,欢迎采纳,祝学习愉快~
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星