相信大家在一些网站上也见过一些特效,例如全屏滚动,模块淡入,接下来就让我来详细的讲解一波吧
全屏滚动
顾名思义,就是将浏览器窗口分为几块,每次触发一个模块,然后一个模块一个模块来进行切换
示例如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
| <!DOCTYPE HTML>
<html>
<head>
<title>爱前端博客</title>
<meta charset="utf-8">
<meta name="Author" content="">
<style type='text/css'>
* {
margin: 0;
padding: 0;
}
body,
html {
height: 100%;
}
body {
overflow: hidden;
}
#wrap {
width: 100%;
height: 100%;
}
#wrap .part {
width: 100%;
height: 100%;
position: relative;
}
#wrap .part .logo {
width: 215px;
height: 60px;
background: url(img/logo.png) top left/100% 100%;
position: absolute;
top: 20px;
left: 20px;
}
#wrap .img1 {
position: absolute;
transition: 1.2s;
}
#wrap .part1 .img1 {
top: 50%;
margin-top: -300px;
left: 50%;
margin-left: -315px;
opacity: 0;
}
#wrap .part2 .img1 {
top: 50%;
margin-top: 0px;
left: 50%;
margin-left: -315px;
opacity: 0;
}
#wrap .part3 .img1 {
top: 50%;
margin-top: -110px;
left: -30px;
opacity: 0;
}
#wrap .part1 .img1.on {
top: 50%;
margin-top: -120px;
left: 50%;
margin-left: -315px;
opacity: 1;
}
#wrap .part2 .img1.on {
top: 50%;
margin-top: -225px;
left: 50%;
margin-left: -315px;
opacity: 1;
}
#wrap .part3 .img1.on {
top: 50%;
margin-top: -110px;
left: 100px;
opacity: 1;
}
#wrap .part img {
display: block;
}
#slide {
width: 20px;
height: 160px;
position: fixed;
top: 50%;
margin-top: -80px;
left: 30px;
}
#slide ul li {
width: 16px;
height: 16px;
border: 2px solid #fff;
margin: 3px 0;
border-radius: 100%;
list-style: none;
cursor: pointer;
}
#slide ul li.on {
background: #fff;
}
</style>
</head>
<body>
<div id='wrap'>
<div class="part part1">
<div class='img1'><img src='img/1-2.png' width='630' height='250'></div>
</div>
<div class="part part2">
<div class='img1'><img src='img/2-2.png' width='630' height='450'></div>
</div>
<div class="part part3">
<div class='img1'><img src='img/3-2.png' width='570' height='220'></div>
</div>
<div class="part part4"></div>
<div class="part part5"></div>
<div class="part part6"></div>
<div class="part part7"></div>
</div>
<div id="slide">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="js/jquery.mousewheel.js"></script>
<script type="text/javascript">
setTimeout(function () {
$(document).scrollTop(0);
}, 50);
var $part = $('.part');
var $li = $('#slide ul li');
var $img = $('.part img');
//初始化
(function () {
$li.eq(0).addClass('on');
$part.append('<div class="logo"></div>');
$part.each(function (i) {
var str = i != 1 ? 'url(img/' + (i + 1) + '.jpg) no-repeat center / cover' : '#D97F5C';
$(this).css('background', str);
});
})();
//页面滚动
(function () {
var index = 0;
var wH = $(window).height();
var nowTime = new Date();
$(window).resize(function () {
wH = $(window).height();
});
$li.click(function () {
index = $(this).index();
move();
});
$(document).mousewheel(function () {
if (new Date() - nowTime > 500) {
nowTime = new Date();
var d = arguments[1];
index = d < 0 ? (index >= $li.length - 1 ? 0 : index + 1) : (index <= 0 ? $li.length - 1 : index - 1);
move();
};
});
function move() {
$li.eq(index).addClass('on').siblings().removeClass('on');
$('body,html').animate({
scrollTop: index * wH
}, 500, function () {
$part.eq(index).find('.img1').addClass('on');
$part.eq(index).siblings().find('.img1').removeClass('on');
});
}
})();
//图片加载完后盒子居中
</script>
</body>
</html> |
模块淡入
顾名思义,就是进入某个模块的时候,触发某一个动画效果
示例如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
img{
border:0;
}
ol, ul ,li{list-style: none;}
.box {
transition:all 1s;
position: absolute;
left:0;
top:50%;
margin:-100px 0 0 -200px;
width: 200px;
height:200px;
background: red;
}
.on {
margin-left:500px;
}
</style>
</head>
<body>
<div class="box">
模块淡入
</div>
</body>
</html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
setTimeout(()=>{
$('.box').addClass("on");
},3000)
</script> |
js全屏滚动_模块淡入效果请猛戳此处:点击
js全屏滚动_模块淡入请请猛戳此处:下载
「梦想一旦被付诸行动,就会变得神圣,如果觉得我的文章对您有用,请帮助本站成长」
共 0 条评论关于"js全屏滚动_模块淡入"
最新评论