康诺科技java培训小课堂:Web前端——横向切换屏幕
康诺科技java培训小课堂:Web前端——横向切换屏幕
用到的知识点:html+css+js。
实现的效果:横向切换屏幕
源码:<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>横向滚屏效果</title>
<link href="css/style.css"rel="stylesheet" type="text/css">
<script type="text/javascript"src="js/jquery-1.10.2.js"></script>
<script type="text/javascript"src="js/jquery.touchSwipe.js"></script>
<script type="text/javascript"src="js/jquery.horizonScroll.js"></script>
</head>
<body>
<header data-role="header"id="header">
<nav>
<ul>
<li>
<ahref="#section-section1"><span>第一屏</span></a>
</li>
<li>
<ahref="#section-section2"><span>第二屏</span></a>
</li>
<li>
<ahref="#section-section3"><span>第三屏</span></a>
</li>
<li>
<ahref="#section-section4"><span>第四屏</span></a>
</li>
</ul>
</nav>
</header>
<divclass="horizon-prev"><imgsrc="images/l-arrow.png"></div>
<divclass="horizon-next"><imgsrc="images/r-arrow.png"></div>
<section data-role="section"id="section-section1">
<divval="section-section2">第一屏</div>
</section>
<section data-role="section"id="section-section2">
<divval="section-section3">第二屏</div>
</section>
<section data-role="section"id="section-section3">
<divval="section-section4">第三屏</div>
</section>
<section data-role="section"id="section-section4">
<divval="section-section4">第四屏</div>
</section>
<scripttype="text/javascript">
//鼠标滑动触发或手机触屏触摸横屏滚动效果
$('section').horizon({swipe: true});
</script>
</body>
</html>
style.css源码:html, body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
overflow: hidden;
}
section, header,footer, nav, div, span, ul, li, a {
box-sizing: border-box;
}
header {
position: fixed;
top: 0;
right: 0;
left: 0;
background-color: #f2f2f2;
}
header nav {
}
header ul {
margin: 0;
padding: 0;
list-style: none;
}
header ul li {
display: inline-block;
padding: 0 20px;
}
header ul a {
font-weight: 700;
text-decoration: none;
color: #4d4d4d;
height: 50px;
display: block;
position: relative;
}
header ul a span{
position: relative;
top: 50%;
transform: translateY(-50%);
display: inline-block;
}
section {
float: left;
display: block;
height: 100%;
padding: 75px 0 0 0;
margin: 0;
}
#section-section1{
background: #2c3e50;
}
#section-section2{
background: #16a085;
}
#section-section3{
background: #27ae60;
}
#section-section4{
background: #c0392b;
}
.horizon-prev,.horizon-next {
position: fixed;
top: 50%;
margin-top: -24px;
z-index: 9999;
}
.horizon-prev {
left: 20px;
}
.horizon-next {
right: 20px;
}
文/康诺科技