admin管理员组文章数量:1279008
I have a footer/row of SVGs I made, but they fail to animate during the transition between the 1st and 2nd Sections. The code is not simple to debug because this needs to animate with js controlling the size of a few elements. A number of brave users have e up with solutions that work in Chrome and Firefox, but to get the credit, the solution must work in Safari, too.
I have verified that the classes which I add during transition (.fixed
) are indeed applied, because they are what I use change the size of the SVGs. So while the SVGs change sizes, for some reason I still cannot get the CSS transitions to animate. You can view this failure to animate in the the GIF below.
Footer does not animate:
The elements that I believe need the transition code are the SVGs themselves, which are of class areaSVG
, because they are the ones who are changing from max-height: 18vh
to max-height: 9vh.
However, when I add some animation code to .areaSVG
, it didn't work, so maybe I'm wrong. Here is the transition code I tried adding to the intial SVG (.areaSVG
) settings that failed:
-webkit-transition: max-height 1s;
-moz-transition: max-height 1s;
transition: max-height 1s;
A few months ago, With the help of another, more experienced coder I added a javscript function that at some point animated the SVGs. We used JS to call window.requestAnimationFrame(startAnimation)
, but it no longer works. I mented the parts related to this out, but if you can think JS will be needed to get this to animate, feel free to fork the code pen and play with it. A suitable answer should make the animation work in Safari, Chrome, and Firefox.
Codepens
This is the easiest, minimized version you should troubleshoot with because it is without media queries (as requested by
@Eric N
:This is the full codepen, with media queries:
Selectors
Selectors on the first section (on page top):
- The whole footer:
#indexFooter
- The SVG Parents:
.ey-col-svg
- The SVG itself:
.areaSVG
Selectors on the second section (after scroll 100px down):
- The whole fixed footer:
#indexFooter.fixed
- The fixed SVG Parents:
.ey-col-svg.fixed
- The fixed SVG itself:
.areaSVG.fixed
Note:when the page first loads both the SVG parent (.ey-col-svg
) and the SVG itself (.areaSVG
) are invisible and have the setting display:none
to avoid a weird experience for the user.
Here is the information about the important elements in each section:
Big footer (on the first section)
The inital CSS (First Section)
/* The whole footer container */
#indexFooter {
text-align: center;
box-sizing: border-box;
position: fixed;
vertical-align: middle;
bottom: 0;
left: 0;
z-index: 5000;
max-height: 33.33vh;
width: 100%;
}
/* The SVG container*/
.ey-col-svg {
display: none;
height: auto;
text-align: center;
box-sizing: border-box;
padding: 0;
}
/* The SVG */
.areaSVG {
display: none;
max-height: 18vh;
box-sizing: content-box;
margin: 0;
}
Next, the JS runs and then displays the elements (still on the first section):
/* The SVG container*/
.ey-col-svg {
display: block;
}
/* The SVG*/
.areaSVG {
display: inline-block;
}
Small Footer (while below the first section)
After leaving the first section (when the footer should be smaller and fixed)
/* The SVG when low on page*/
.areaSVG.fixed {
max-height: 9vh;
}
Javascript/jQuery
Here is the Javascript if you want to see it
$(document).ready(function() {
var sectionIndex = 1;
var animationName = 'indexAnimateLand';
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();
resizeLanding();
});
//sizes the landing image and the icons
function startAnimation() {
$('.ey-col-svg').css('display', 'block');
$('.areaSVG').css('display', 'inline-block');
resizeLanding(); // resize the background image
// window.requestAnimationFrame(startAnimation); //animate
} // end start Animation
//resizes the landing image and sets top margin for the following section
function resizeLanding() {
var $lndFooter = $('#indexFooter');
var $bgLand = $('#section0img');
var $contactSection = $('#section2Div');
var winHeight = $(window).height();
var lndFooterHeight = $lndFooter.height();
bgFinalHeight = winHeight - lndFooterHeight;
$bgLand.css("height", bgFinalHeight);
$contactSection.css("margin-top", bgFinalHeight);
}
// changes the .css classes depending on section,
//(also triggers landing image resize if necessary)
function toggleIntroClass(){
var winHeight = $(window).height();
var heightThreshold = $("#section0").offset().top;
var heightThreshold_end = $("#section0").offset().top + $("#section0").height();
$(window).scroll(function() {
var scroll = $(window).scrollTop();
//if user hasn't scrolled past 100px/the first section, adjust classes
if (scroll <= 100)
// (scroll >= heightThreshold && scroll < heightThreshold_end )
{
sectionIndex = 1;
$('#newHeader').removeClass('fixed');
$('#nameBoxIndexTop').removeClass('fixed');
$('#indexIconsContainer').removeClass('fixed');
$('#indexIconsList').removeClass('fixed');
$('#linkCell').removeClass('fixed');
$('#indexFooter').removeClass('fixed');
$('.ey-text-content').removeClass('fixed');
$('.ey-col-svg').removeClass('fixed');
$('.ey-col-1').removeClass('fixed');
$('.ey-row-scale').removeClass('fixed');
$('.ey-nav-bar').removeClass('fixed');
$('.areaSVG').attr("class", "areaSVG");
}
//else if they have scrolled past the first hundred pixels/first section, adjust classes
else {
sectionIndex = 2;
$('#newHeader').addClass('fixed');
$('#nameBoxIndexTop').addClass('fixed');
$('#indexIconsContainer').addClass('fixed');
$('#indexIconsList').addClass('fixed');
$('#linkCell').addClass('fixed');
$('#indexFooter').addClass('fixed');
$('.ey-text-content').addClass('fixed');
$('.ey-col-svg').addClass('fixed');
$('.ey-col-1').addClass('fixed');
$('.ey-row-scale').addClass('fixed');
$('.ey-nav-bar').addClass('fixed');
$('.areaSVG').attr("class", "areaSVG fixed");
}
}); //end inner scroll Function
};//end intro Class toggle function
});//end document ready
Any help would be appreciated! Thanks!
I have a footer/row of SVGs I made, but they fail to animate during the transition between the 1st and 2nd Sections. The code is not simple to debug because this needs to animate with js controlling the size of a few elements. A number of brave users have e up with solutions that work in Chrome and Firefox, but to get the credit, the solution must work in Safari, too.
I have verified that the classes which I add during transition (.fixed
) are indeed applied, because they are what I use change the size of the SVGs. So while the SVGs change sizes, for some reason I still cannot get the CSS transitions to animate. You can view this failure to animate in the the GIF below.
Footer does not animate:
The elements that I believe need the transition code are the SVGs themselves, which are of class areaSVG
, because they are the ones who are changing from max-height: 18vh
to max-height: 9vh.
However, when I add some animation code to .areaSVG
, it didn't work, so maybe I'm wrong. Here is the transition code I tried adding to the intial SVG (.areaSVG
) settings that failed:
-webkit-transition: max-height 1s;
-moz-transition: max-height 1s;
transition: max-height 1s;
A few months ago, With the help of another, more experienced coder I added a javscript function that at some point animated the SVGs. We used JS to call window.requestAnimationFrame(startAnimation)
, but it no longer works. I mented the parts related to this out, but if you can think JS will be needed to get this to animate, feel free to fork the code pen and play with it. A suitable answer should make the animation work in Safari, Chrome, and Firefox.
Codepens
This is the easiest, minimized version you should troubleshoot with because it is without media queries (as requested by
@Eric N
:http://codepen.io/ihatecoding/pen/LREOPWThis is the full codepen, with media queries: http://codepen.io/ihatecoding/pen/ALjKKz
Selectors
Selectors on the first section (on page top):
- The whole footer:
#indexFooter
- The SVG Parents:
.ey-col-svg
- The SVG itself:
.areaSVG
Selectors on the second section (after scroll 100px down):
- The whole fixed footer:
#indexFooter.fixed
- The fixed SVG Parents:
.ey-col-svg.fixed
- The fixed SVG itself:
.areaSVG.fixed
Note:when the page first loads both the SVG parent (.ey-col-svg
) and the SVG itself (.areaSVG
) are invisible and have the setting display:none
to avoid a weird experience for the user.
Here is the information about the important elements in each section:
Big footer (on the first section)
The inital CSS (First Section)
/* The whole footer container */
#indexFooter {
text-align: center;
box-sizing: border-box;
position: fixed;
vertical-align: middle;
bottom: 0;
left: 0;
z-index: 5000;
max-height: 33.33vh;
width: 100%;
}
/* The SVG container*/
.ey-col-svg {
display: none;
height: auto;
text-align: center;
box-sizing: border-box;
padding: 0;
}
/* The SVG */
.areaSVG {
display: none;
max-height: 18vh;
box-sizing: content-box;
margin: 0;
}
Next, the JS runs and then displays the elements (still on the first section):
/* The SVG container*/
.ey-col-svg {
display: block;
}
/* The SVG*/
.areaSVG {
display: inline-block;
}
Small Footer (while below the first section)
After leaving the first section (when the footer should be smaller and fixed)
/* The SVG when low on page*/
.areaSVG.fixed {
max-height: 9vh;
}
Javascript/jQuery
Here is the Javascript if you want to see it
$(document).ready(function() {
var sectionIndex = 1;
var animationName = 'indexAnimateLand';
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();
resizeLanding();
});
//sizes the landing image and the icons
function startAnimation() {
$('.ey-col-svg').css('display', 'block');
$('.areaSVG').css('display', 'inline-block');
resizeLanding(); // resize the background image
// window.requestAnimationFrame(startAnimation); //animate
} // end start Animation
//resizes the landing image and sets top margin for the following section
function resizeLanding() {
var $lndFooter = $('#indexFooter');
var $bgLand = $('#section0img');
var $contactSection = $('#section2Div');
var winHeight = $(window).height();
var lndFooterHeight = $lndFooter.height();
bgFinalHeight = winHeight - lndFooterHeight;
$bgLand.css("height", bgFinalHeight);
$contactSection.css("margin-top", bgFinalHeight);
}
// changes the .css classes depending on section,
//(also triggers landing image resize if necessary)
function toggleIntroClass(){
var winHeight = $(window).height();
var heightThreshold = $("#section0").offset().top;
var heightThreshold_end = $("#section0").offset().top + $("#section0").height();
$(window).scroll(function() {
var scroll = $(window).scrollTop();
//if user hasn't scrolled past 100px/the first section, adjust classes
if (scroll <= 100)
// (scroll >= heightThreshold && scroll < heightThreshold_end )
{
sectionIndex = 1;
$('#newHeader').removeClass('fixed');
$('#nameBoxIndexTop').removeClass('fixed');
$('#indexIconsContainer').removeClass('fixed');
$('#indexIconsList').removeClass('fixed');
$('#linkCell').removeClass('fixed');
$('#indexFooter').removeClass('fixed');
$('.ey-text-content').removeClass('fixed');
$('.ey-col-svg').removeClass('fixed');
$('.ey-col-1').removeClass('fixed');
$('.ey-row-scale').removeClass('fixed');
$('.ey-nav-bar').removeClass('fixed');
$('.areaSVG').attr("class", "areaSVG");
}
//else if they have scrolled past the first hundred pixels/first section, adjust classes
else {
sectionIndex = 2;
$('#newHeader').addClass('fixed');
$('#nameBoxIndexTop').addClass('fixed');
$('#indexIconsContainer').addClass('fixed');
$('#indexIconsList').addClass('fixed');
$('#linkCell').addClass('fixed');
$('#indexFooter').addClass('fixed');
$('.ey-text-content').addClass('fixed');
$('.ey-col-svg').addClass('fixed');
$('.ey-col-1').addClass('fixed');
$('.ey-row-scale').addClass('fixed');
$('.ey-nav-bar').addClass('fixed');
$('.areaSVG').attr("class", "areaSVG fixed");
}
}); //end inner scroll Function
};//end intro Class toggle function
});//end document ready
Any help would be appreciated! Thanks!
Share Improve this question edited Jan 7, 2018 at 18:04 YakovL 8,36513 gold badges73 silver badges112 bronze badges asked Sep 4, 2016 at 22:37 CoderScissorhandsCoderScissorhands 4951 gold badge9 silver badges28 bronze badges 9- I'd suggest isolating just this footer to begin debugging. There is a lot of other things in this example to obfuscate what directly applies to the footer. – Eric N Commented Sep 5, 2016 at 15:32
- Thanks, you are right. I added a codepen in which I deleted my media queries, I hope that helps! – CoderScissorhands Commented Sep 5, 2016 at 15:40
-
(I need to keep the js that controls the background image there, as well as the background image and sections, because the final footer will need to work with the js that uses the landing footer height to determine the height of the landing background image,
#section0img
.) – CoderScissorhands Commented Sep 5, 2016 at 15:58 -
I find this to be truly bizarre, because I tried to do this with an
@keyframes
animation rather than transition onmax-height
and it appears to work: codepen.io/anon/pen/QKbVjb Is this what it used to look like? Is this the exact code that used to work? The animation still looks a bit funky. – skyline3000 Commented Sep 8, 2016 at 13:23 - Thanks, you managed to create break this is a way that might help someone to further debug. Do you notice that in your animation, the SVGs are not staying large when landing? The desired result is only one transition when scrolling down or scrolling back up, and one transition from large to small when scolling down, and transition from small to large when scrolling up. But in your codepen the SVGs transition from large to small even immediately when loading/on the top of the page, before any downscroll. They should never be small when the user is on the top of the page. – CoderScissorhands Commented Sep 8, 2016 at 14:26
4 Answers
Reset to default 3 +100I have a cross-browser solution here: http://codepen.io/anon/pen/EgZzxo
It is not perfect: there are some issues with changing width, but the question you posted is answered I believe. To fix the other issues you have to look at your css
to see if some elements are not changing the display
property - that may mess up with your transitions. Also fixing the widths should help so they are not dependent on the text size - it will change when the text gets smaller so the position of the other elements will change with it.
The main problem you had was that .ey-row-scale.fixed
had display: inline-block
while .ey-row.scale
hadn't. That was one thing that was breaking the transition. The other was that the transition has to be defined on the svg
element, so instead of:
.indexAnimateLand {
}
I had to do:
.indexAnimateLand svg {
}
and then it worked. Not sure exactly why, but it may be down to the inline svg not inherting the styles correctly.
I also added transitions to the text elements and had to untangle some !important
margins you put in there.
In general the code could be improved in a few areas:
- Don't mix inline styling with css stylesheets, as it is very difficult to know what es from where
- Try to put mon classes close to each other in the css file, so it's easier to see what is the difference when you add a
.fixed
class for example - Different units serve different purposes.
font-size
shouldn't be defined invh
as that's relative to screen size and can make the text unreadable - Use
!important
sparingly, or better, don't use at all. Oftentimes the code can be cleaner if you fix the problems that force you to use!important
in the first place
I think I've done something nice with the animation of your navigation menu.
The first thing I've done is to clean the code from everything that looked unused... Obviously due to the multiple previous attempts.
Removing unused CSS classes and unused js kind of "reduced" the line amount.
I also renamed some of the remaining classes with more significative names...
Because I was lost.
I managed to fix "jumpy effect" of the animation (I started from the last CodePen you posted in ments) to make the movement look real smooth. I mostly did it with CSS.
The results
See on CodePen and on my server
Perfect result on:
- Chrome 53
- Opera 40
- FireFox 49
Eye icons are 30% below the screen on:
(But may look like intended!):
- Safari for Windows 5.1.7
I couldn't test it on Safari 10 since I don't own any Apple device. - Samsung browser (Samsung Galaxy S3)
Really subtile "jumpy" effect of the background image on:
(when animation triggers)
- Chrome for Android (Samsung Galaxy S3)
Bad strangenesses in the animation:
(but both minimised and expanded states are ok)
- Explorer 11 (I hate IE!)
For browsers that doesn't support viewport units (vh, vw, etc.) like Safari for windows and Samsung browser, I found Saabi, a CSS polyfill, to "almost" get it right. It's not perfect, but real close.
Other browsers support viewport units, including IOS Safari 10.
Notice that there are errors thrown by Saabi in console, which I didn't fixed.
I think the result is Saabi to not pletely parse the CSS file.
But since it almost fixes some browsers without affecting the others (Saabi run only if the browser doesn't support viewport units)... It is worthy.
I used it on my server, but couldn't on CodePen because I didn't find a CDN.
About IE...
The problem es from something else not (or badly) supported...
I didn't figured out what.
I tested the js with JSHint and the CSS with CSSLint.
There are minor issues due to your SVG in the CSS checker.
There are also in the W3C markup validator, due to that.
I suggest you create PNGs from your SVG to remove those errors.
These errors may be the cause of the remaning display issues on Safari for Windows and Samsung Browser. Saabi stucks on something... And I think it may be your "Eye icons" SVGs.
Feel free to ask about any change I made.
;)
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/2000/svg" xmlns="http://www.w3/2000/svg" xmlns:xlink="http://www.w3/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/2000/svg" xmlns="http://www.w3/2000/svg" xmlns:xlink="http://www.w3/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/2000/svg" xmlns="http://www.w3/2000/svg" xmlns:xlink="http://www.w3/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/2000/svg" xmlns="http://www.w3/2000/svg" xmlns:xlink="http://www.w3/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>
And the part to add, to use the polyfill:
(right above </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 pStyle = parseInt((window.getComputedStyle ?
getComputedStyle(elem, null) :
elem.currentStyle).width, 10);
//console.log(width);
//console.log(pStyle);
if(!width==pStyle){
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;
}
http://codepen.io/stephendesjardins/pen/wzEVrQ
.ey-col-svg {
height: auto;
text-align: center;
box-sizing: border-box;
padding: 0;
position:relative;
height:100px;
transition:height 0.3s;
}
.fixed .ey-col-svg {
height:50px;
}
.fixed .ey-text-content {
display:none;
}
/*this is the container for the bottom svg */
.areaSVG {
box-sizing: content-box;
margin: 0;
position:absolute;
height:100%;
width:100%;
z-index:10;
left:0;
top:0;
}
You can tweak it but here is the gist of it. Instead of doing transition height on the svg, do it on the parent div. Also, just add a height on it and put your svg absolute inside it. I don't see why this should be dynamic with max-height. The icons and text will never exceed more height in this particular example.
I hope this helps
Please Do the following in your link (http://codepen.io/ihatecoding/pen/LREOPW):
Add this class in your CSS:
.animated {transition: all .6s ease-in-out;}
I have edited your JS code which is stated below. Kindly replace this "if else" block starting from line 75 in your codepen link's js part:
if (scroll <= 100){ sectionIndex = 1; $(".ey-col-1").css("transform","scale(1)"); }else{ sectionIndex = 2; $(".ey-col-1").addClass("animated").css("transform","scale(0.6)"); }
本文标签: javascriptSVGs change size but won39t animate on scroll transitionStack Overflow
版权声明:本文标题:javascript - SVGs change size but won't animate on scroll transition - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741290439a2370517.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论