我认为我在导航菜单的动画方面做得不错。
我做的第一件事是清除所有看起来未使用的代码......显然是由于之前的多次尝试。
删除未使用的 CSS 类和未使用的 js 有点“减少”行数。
我还用更有意义的名称重命名了剩余的一些类...
因为我迷路了。
我设法修复了动画的“跳跃效果”(我从 cmets 中的 the last CodePen you posted 开始) 使运动看起来非常流畅。我主要是用 CSS 做的。
结果
见on CodePen和on my server
完美的结果:
眼睛图标位于屏幕下方 30% 的位置:
(但可能看起来像预期的那样!):
- 适用于 Windows 5.1.7 的 Safari
由于我没有任何 Apple 设备,因此无法在 Safari 10 上对其进行测试。
- 三星浏览器(三星 Galaxy S3)
真正微妙的“跳跃”效果的背景图片:
(动画触发时)
- Chrome for Android(三星 Galaxy S3)
动画中的怪异之处:
(但最小化和展开状态都可以)
对于不支持视口单元(vh、vw 等)的浏览器,例如 Windows 版 Safari 和三星浏览器,我发现 Saabi,一个 CSS 填充程序,“几乎”可以做到。它并不完美,但非常接近。
其他浏览器support viewport units,包括IOS Safari 10。
注意 Saabi 在控制台中抛出了错误,我没有修复。
我认为结果是 Saabi 没有完全解析 CSS 文件。
但由于它几乎修复了一些浏览器而不影响其他浏览器(Saabi 仅在浏览器不支持视口单元时运行)......这是值得的。
我在我的服务器上使用它,但在 CodePen 上无法使用,因为我没有找到 CDN。
关于 IE...
问题来自其他不受(或严重)支持的东西...
不知道是什么。
我用JSHint 测试了js,用CSSLint 测试了CSS。
由于您的 SVG 在 CSS 检查器中存在一些小问题。
也有在W3C markup validator,因之。
我建议您从 SVG 创建 PNG 以消除这些错误。
这些错误可能是导致 Safari for Windows 和 Samsung Browser 出现剩余显示问题的原因。 Saabi 卡在某些东西上……我认为这可能是您的“眼睛图标”SVG。
请随时询问我所做的任何更改。
;)
HTML:
<div id="whole">
<div id="nav-panel" class="indexRow minimise-smooter">
<!-- fancy icon footer -->
<div id="nav-title" class="indexRow minimise-smooter">
LINKS
</div>
<div class="nav-eyes minimise-smooter indexRow">
<div class="indexAnimateLand indexRow">
<div class="eye-outer-div indexRow">
<a class="eSVG areaAnchor indexRow" href="e.html">
<div class="eye-inner-div indexRow">
<svg class="SVG" x="0px" y="0px" viewBox="0 0 80 80" perserveAspectRatio="xMidYMid meet" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<filter id="f1" x="0" y="0" width="200%" height="200%">
<feOffset result="offOut" in="SourceAlpha" dx="3" dy="3" ></feOffset>
<feGaussianBlur result="blurOut" in="offOut" stdDeviation="2" ></feGaussianBlur>
<feBlend in="SourceGraphic" in2="blurOut" mode="normal" ></feBlend>
</filter>
</defs><path id="circle-background" opacity="0.4196" fill="#FFFFFF" enable-background="new " d="
M4.193,37.492c0-18.987,15.419-34.38,34.44-34.38c19.021,0,34.439,15.393,34.439,34.38c0,18.987-15.418,34.381-34.439,34.381
C19.613,71.873,4.193,56.48,4.193,37.492L4.193,37.492z" filter="url(#f1)" ></path>
<path id="sclera" class="fillWhite" fill-rule="evenodd" clip-rule="evenodd" stroke-width="0.25" stroke-miterlimit="8" d="
M11.41,38.895c27.619-31.029,41.313-9.542,49.646-2.012c-4.306,6.07-12.69,27.49-46.392,9.919c0,0-5.375-3.548-5.641-4.75
C12.787,37.379,11.41,38.895,11.41,38.895z" ></path>
<ellipse id="iris" class="fillDark" fill-rule="evenodd" clip-rule="evenodd" cx="38.196" cy="36.63" rx="16.202" ry="15.686" ></ellipse>
<ellipse id="pupil" class="fillWhite" fill-rule="evenodd" clip-rule="evenodd" cx="38.529" cy="36.954" rx="5.628" ry="5.449" ></ellipse>
<path id="eyelid" class="fillDark" fill-rule="evenodd" clip-rule="evenodd" stroke-width="0.25" stroke-miterlimit="8" d="
M56.955,26.227c5.438,2.787,12.803,9.595,12.803,9.595s-2.338,3.235-5.677,2.588c-4.027,3.396-13.345,29.705-49.417,8.393
c33.702,17.571,42.086-3.849,46.392-9.919c-8.333-7.53-22.026-29.018-49.646,2.012c0,0-2.94,1.806-4.112-1.456
c-1.172-3.261,2.481-0.477,4.009-2.911c1.527-2.434,3.674-3.557,7.682-6.792c-4.008,0.646-7.348,3.558-7.348,3.558
c10.521-10.835,31.379-17.498,53.107-4.205C64.748,27.089,59.404,26.119,56.955,26.227z" ></path>
</svg>
</div>
<div class="eye-text indexRow minimise-smooter">LINK 1</div>
</a>
</div>
<div class="eye-outer-div indexRow">
<a class="eSVG areaAnchor indexRow" href="e.html">
<div class="eye-inner-div indexRow">
<svg class="SVG" x="0px" y="0px" viewBox="0 0 80 80" perserveAspectRatio="xMidYMid meet" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<filter id="f1" x="0" y="0" width="200%" height="200%">
<feOffset result="offOut" in="SourceAlpha" dx="3" dy="3" ></feOffset>
<feGaussianBlur result="blurOut" in="offOut" stdDeviation="2" ></feGaussianBlur>
<feBlend in="SourceGraphic" in2="blurOut" mode="normal" ></feBlend>
</filter>
</defs><path id="circle-background" opacity="0.4196" fill="#FFFFFF" enable-background="new " d="
M4.193,37.492c0-18.987,15.419-34.38,34.44-34.38c19.021,0,34.439,15.393,34.439,34.38c0,18.987-15.418,34.381-34.439,34.381
C19.613,71.873,4.193,56.48,4.193,37.492L4.193,37.492z" filter="url(#f1)" ></path>
<path id="sclera" class="fillWhite" fill-rule="evenodd" clip-rule="evenodd" stroke-width="0.25" stroke-miterlimit="8" d="
M11.41,38.895c27.619-31.029,41.313-9.542,49.646-2.012c-4.306,6.07-12.69,27.49-46.392,9.919c0,0-5.375-3.548-5.641-4.75
C12.787,37.379,11.41,38.895,11.41,38.895z" ></path>
<ellipse id="iris" class="fillDark" fill-rule="evenodd" clip-rule="evenodd" cx="38.196" cy="36.63" rx="16.202" ry="15.686" ></ellipse>
<ellipse id="pupil" class="fillWhite" fill-rule="evenodd" clip-rule="evenodd" cx="38.529" cy="36.954" rx="5.628" ry="5.449" ></ellipse>
<path id="eyelid" class="fillDark" fill-rule="evenodd" clip-rule="evenodd" stroke-width="0.25" stroke-miterlimit="8" d="
M56.955,26.227c5.438,2.787,12.803,9.595,12.803,9.595s-2.338,3.235-5.677,2.588c-4.027,3.396-13.345,29.705-49.417,8.393
c33.702,17.571,42.086-3.849,46.392-9.919c-8.333-7.53-22.026-29.018-49.646,2.012c0,0-2.94,1.806-4.112-1.456
c-1.172-3.261,2.481-0.477,4.009-2.911c1.527-2.434,3.674-3.557,7.682-6.792c-4.008,0.646-7.348,3.558-7.348,3.558
c10.521-10.835,31.379-17.498,53.107-4.205C64.748,27.089,59.404,26.119,56.955,26.227z" ></path>
</svg>
</div>
<div class="eye-text indexRow minimise-smooter">LINK 2</div>
</a>
</div>
<div class="eye-outer-div indexRow">
<a class="eSVG areaAnchor indexRow" href="e.html">
<div class="eye-inner-div indexRow">
<svg class="SVG" x="0px" y="0px" viewBox="0 0 80 80" perserveAspectRatio="xMidYMid meet" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<filter id="f1" x="0" y="0" width="200%" height="200%">
<feOffset result="offOut" in="SourceAlpha" dx="3" dy="3" ></feOffset>
<feGaussianBlur result="blurOut" in="offOut" stdDeviation="2" ></feGaussianBlur>
<feBlend in="SourceGraphic" in2="blurOut" mode="normal" ></feBlend>
</filter>
</defs><path id="circle-background" opacity="0.4196" fill="#FFFFFF" enable-background="new " d="
M4.193,37.492c0-18.987,15.419-34.38,34.44-34.38c19.021,0,34.439,15.393,34.439,34.38c0,18.987-15.418,34.381-34.439,34.381
C19.613,71.873,4.193,56.48,4.193,37.492L4.193,37.492z" filter="url(#f1)" ></path>
<path id="sclera" class="fillWhite" fill-rule="evenodd" clip-rule="evenodd" stroke-width="0.25" stroke-miterlimit="8" d="
M11.41,38.895c27.619-31.029,41.313-9.542,49.646-2.012c-4.306,6.07-12.69,27.49-46.392,9.919c0,0-5.375-3.548-5.641-4.75
C12.787,37.379,11.41,38.895,11.41,38.895z" ></path>
<ellipse id="iris" class="fillDark" fill-rule="evenodd" clip-rule="evenodd" cx="38.196" cy="36.63" rx="16.202" ry="15.686" ></ellipse>
<ellipse id="pupil" class="fillWhite" fill-rule="evenodd" clip-rule="evenodd" cx="38.529" cy="36.954" rx="5.628" ry="5.449" ></ellipse>
<path id="eyelid" class="fillDark" fill-rule="evenodd" clip-rule="evenodd" stroke-width="0.25" stroke-miterlimit="8" d="
M56.955,26.227c5.438,2.787,12.803,9.595,12.803,9.595s-2.338,3.235-5.677,2.588c-4.027,3.396-13.345,29.705-49.417,8.393
c33.702,17.571,42.086-3.849,46.392-9.919c-8.333-7.53-22.026-29.018-49.646,2.012c0,0-2.94,1.806-4.112-1.456
c-1.172-3.261,2.481-0.477,4.009-2.911c1.527-2.434,3.674-3.557,7.682-6.792c-4.008,0.646-7.348,3.558-7.348,3.558
c10.521-10.835,31.379-17.498,53.107-4.205C64.748,27.089,59.404,26.119,56.955,26.227z" ></path>
</svg>
</div>
<div class="eye-text indexRow minimise-smooter">LINK 3</div>
</a>
</div>
<div class="eye-outer-div indexRow">
<a class="eSVG areaAnchor indexRow" href="e.html">
<div class="eye-inner-div indexRow">
<svg class="SVG" x="0px" y="0px" viewBox="0 0 80 80" perserveAspectRatio="xMidYMid meet" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<filter id="f1" x="0" y="0" width="200%" height="200%">
<feOffset result="offOut" in="SourceAlpha" dx="3" dy="3" ></feOffset>
<feGaussianBlur result="blurOut" in="offOut" stdDeviation="2" ></feGaussianBlur>
<feBlend in="SourceGraphic" in2="blurOut" mode="normal" ></feBlend>
</filter>
</defs><path id="circle-background" opacity="0.4196" fill="#FFFFFF" enable-background="new " d="
M4.193,37.492c0-18.987,15.419-34.38,34.44-34.38c19.021,0,34.439,15.393,34.439,34.38c0,18.987-15.418,34.381-34.439,34.381
C19.613,71.873,4.193,56.48,4.193,37.492L4.193,37.492z" filter="url(#f1)" ></path>
<path id="sclera" class="fillWhite" fill-rule="evenodd" clip-rule="evenodd" stroke-width="0.25" stroke-miterlimit="8" d="
M11.41,38.895c27.619-31.029,41.313-9.542,49.646-2.012c-4.306,6.07-12.69,27.49-46.392,9.919c0,0-5.375-3.548-5.641-4.75
C12.787,37.379,11.41,38.895,11.41,38.895z" ></path>
<ellipse id="iris" class="fillDark" fill-rule="evenodd" clip-rule="evenodd" cx="38.196" cy="36.63" rx="16.202" ry="15.686" ></ellipse>
<ellipse id="pupil" class="fillWhite" fill-rule="evenodd" clip-rule="evenodd" cx="38.529" cy="36.954" rx="5.628" ry="5.449" ></ellipse>
<path id="eyelid" class="fillDark" fill-rule="evenodd" clip-rule="evenodd" stroke-width="0.25" stroke-miterlimit="8" d="
M56.955,26.227c5.438,2.787,12.803,9.595,12.803,9.595s-2.338,3.235-5.677,2.588c-4.027,3.396-13.345,29.705-49.417,8.393
c33.702,17.571,42.086-3.849,46.392-9.919c-8.333-7.53-22.026-29.018-49.646,2.012c0,0-2.94,1.806-4.112-1.456
c-1.172-3.261,2.481-0.477,4.009-2.911c1.527-2.434,3.674-3.557,7.682-6.792c-4.008,0.646-7.348,3.558-7.348,3.558
c10.521-10.835,31.379-17.498,53.107-4.205C64.748,27.089,59.404,26.119,56.955,26.227z" ></path>
</svg>
</div>
<div class="eye-text indexRow minimise-smooter">LINK 4</div>
</a>
</div>
</div>
</div>
</div>
<div id="fullpage">
<article>
<section id="section0">
<!-- content inside of landing section (except for icons) -->
<div id="section0img">
</div>
</section>
<section id="section2">
<div id="section2Div">
<h1><a id="contact">Section 2</a></h1>
</div>
</section>
<section id="section3">
<h1>Section 3</h1>
</section>
</article>
</div>
</div>
以及要添加的部分,以使用 polyfill:
(就在 </body> 上方)
<!-- Saabi -->
<div id="viewport-unit-tester" style="opacity:0; height:1px; width:50vw;"></div>
<script>
// test if the browser can handle viewport unit.
// If not, it load Saabi, a polyfill CSS viewport unit.
var elem = document.getElementById("viewport-unit-tester");
var width = parseInt(window.innerWidth / 2, 10);
var compStyle = parseInt((window.getComputedStyle ?
getComputedStyle(elem, null) :
elem.currentStyle).width, 10);
//console.log(width);
//console.log(compStyle);
if(!width==compStyle){
console.log("This browser doesn't support viewport units.");
}else{
console.log("This browser supports viewport units.");
}
if (!Array.prototype.filter)
{
Array.prototype.filter = function(fun /*, thisp*/)
{
var len = this.length;
if (typeof fun != "function")
throw new TypeError();
var res = new Array();
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in this)
{
var val = this[i]; // in case fun mutates this
if (fun.call(thisp, val, i, this))
res.push(val);
}
}
return res;
};
}
</script>
<script src="saabi/tokenizer.js"></script>
<script src="saabi/parser.js"></script>
<script src="saabi/vminpoly.js"></script>
jQuery / JavaScript:
$(document).ready(function() {
var sectionIndex = 1;
startAnimation(); //includes resizing background image and resizing svgs
toggleIntroClass(); //adds css depending on section of page
// if the user resizes the window, run the animation again, and resize the landing
$(window).on('resize', function(){
startAnimation();
});
//sizes the landing image and the icons
function startAnimation() {
$('.eye-inner-div').css('display', 'block');
$('.SVG').css('display', 'inline-block');
}
// changes the .css classes depending on section,
//(also triggers landing image resize if necessary)
function toggleIntroClass(){
$(window).scroll(function() {
var scroll = $(window).scrollTop();
//if user hasn't scrolled past 100px/the first section, adjust classes
if (scroll <= 100) {
sectionIndex = 1;
$('#nav-title').removeClass('minimised');
$('#nav-panel').removeClass('minimised');
$('.eye-text').removeClass('minimised');
$('.eye-inner-div').removeClass('minimised');
$('.eye-outer-div').removeClass('minimised');
$('.nav-eyes').removeClass('minimised');
$('.SVG').attr("class", "SVG");
}
//else if they have scrolled past the first hundred pixels/first section, adjust classes
else {
sectionIndex = 2;
$('#nav-title').addClass('minimised');
$('#nav-panel').addClass('minimised');
$('.eye-text').addClass('minimised');
$('.eye-inner-div').addClass('minimised');
$('.eye-outer-div').addClass('minimised');
$('.nav-eyes').addClass('minimised');
$('.SVG').attr("class", "SVG minimised");
}
}); //end inner scroll Function
}//end intro Class toggle function
});//end document ready
CSS:
* {
padding: 0;
margin: 0;
}
html,
body {
margin: 0;
padding: 0;
height: auto;
border: none;
font-size: 100%;
}
h1 {
text-align: center;
font-size: 10vh;
font-family: sans-serif;
}
/* ------------------------------------------------------------------------------------------------------------------------- Main sections */
#section0 {
height:100vh;
}
#section2 {
height:100vh;
background-color:red;
}
#section3 {
height:100vh;
background-color:yellow;
}
#section0img {
background: url('https://cdn.pbrd.co/images/cZIoMIenr.png') no-repeat;
-webkit-background-size: 100vw 100vh;
-moz-background-size: 100vw 100vh;
-o-background-size: 100vw 100vh;
background-size: 100vw 100vh;
height:100vh;
}
/* ------------------------------------------------------------------------------------------------------------------------- Navigation panel */
#nav-panel {
text-align: center;
box-sizing: border-box;
position: fixed;
vertical-align: middle;
bottom: 0;
left: 0;
z-index: 500;
max-height: 33.33vh;
width: 100%;
border-top: 0.5vh solid Gray;
border-bottom: 0.5vh solid Gray;
}
.nav-eyes {
width: 100% !important;
max-height: 33.33vh;
overflow: hidden;
text-align: center;
}
.indexRow {
background-color: #FBFBFA;
}
#nav-title {
max-height: 3.33vh;
line-height: 3.33vh;
font-size: 3.33vh;
padding: 2vh;
}
.areaAnchor {
text-decoration: none !important;
text-align: center;
}
.eye-text {
text-rendering: optimizeLegibility;
display: block;
text-align: center;
white-space: nowrap;
max-height: 8vh;
line-height: 3.5vh;
color: black;
z-index: 100;
font-size: 4vh;
margin: 3vh 0 .5vh 0 !important;
}
/* ------------------------------------------------------------------------------------------------------------------------- SVG icons */
.eye-outer-div {
text-align: center !important;
width: 20%;
/*height: 100%;*/
margin: 0;
padding: 0;
display: inline-block;
}
.eye-inner-div {
display: none;
height: auto;
text-align: center;
box-sizing: border-box;
padding: 0;
}
.SVG {
display:none;
max-height: 18vh;
box-sizing: content-box;
margin: 0;
-webkit-animation: SVG 1s forwards;
animation: SVG 1s forwards;
}
@-webkit-keyframes SVG {
100% {
max-height: 18vh;
}
0% {
max-height: 9vh;
}
}
@keyframes SVG {
100% {
max-height: 18vh;
}
0% {
max-height: 9vh;
}
}
/* ------------------------------------------------------------------------------------------------------------------------- minimised */
#nav-panel.minimised {
border-top: 0px solid Gray;
border-bottom: 0px solid Gray;
}
#nav-title.minimised { /* SAME AS .eye-text.minimised */
max-height: 0;
font-size: 0;
color: red;
margin: 0;
padding: 0;
line-height: 0;
}
.nav-eyes.minimised {
max-height: 9vh;
}
.eye-outer-div.minimised {
width: 20%;
max-height:9vh;
padding: 0;
margin: 0;
display: inline-block;
float: none;
/* box-sizing: border-box; */
}
.eye-text.minimised{
max-height: 0;
font-size: 0;
color: red;
margin: 0;
padding: 0;
line-height:0;
}
.SVG.minimised {
-webkit-animation: SVGFixed 1s forwards;
animation: SVGFixed 1s forwards;
}
@-webkit-keyframes SVGFixed {
0% {
max-height: 18vh;
}
100% {
max-height: 9vh;
}
}
@keyframes SVGFixed {
0% {
max-height: 18vh;
}
100% {
max-height: 9vh;
}
}
.minimise-smooter{
-webkit-transition-property: line-height, font-size, max-height, color, padding, margin, border-bottom, border-top;
-moz-transition-property: line-height, font-size, max-height, color, padding, margin, border-bottom, border-top;
-o-transition-property: line-height, font-size, max-height, color, padding, margin, border-bottom, border-top;
transition-property: line-height, font-size, max-height, color, padding, margin, border-bottom, border-top;
-webkit-transition-duration: 1s;
-moz-transition-duration: 1s;
-o-transition-duration: 1s;
transition-duration: 1s;
}
/* ------------------------------------------------------------------------------------------------------------------------- END of minimised */
/* ------------------------------------------------------------------------------------------------------------------------- SVG formatting for the eyes*/
#circle-background {
-moz-filter: box-shadow(3px 3px 2px rgba(0, 0, 0, 0.5));
-webkit-filter: box-shadow(3px 3px 2px rgba(0, 0, 0, 0.5));
filter: box-shadow(3px 3px 2px rgb(0, 0, 0, 0.5));
fill: Gainsboro;
}
.fillDark {
fill: #939598;
}
.fillWhite {
fill: White;
}
.active #circle-background-e,
.active #sclera,
.active #pupil {
fill: rgb(183, 36, 103);
}
.active #eyelid,
.active #iris {
stroke: rgb(183, 36, 103);
}
.active #eyelid,
.active #iris {
fill: white;
}
.active #circle-background-s {
fill: rgb(82, 79, 161);
}
.eSVG #pupil {
fill: Black;
}