- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我制作了 SVG 的页脚/行,但它们在第 1 部分和第 2 部分之间的过渡期间无法设置动画。代码调试起来并不简单,因为这需要用 js 控制一些元素的大小来进行动画处理。 许多勇敢的用户提出了适用于 Chrome 和 Firefox 的解决方案,但要获得荣誉,该解决方案也必须适用于 Safari。
我已验证我在转换期间添加的类 (.fixed
) 确实已应用,因为它们是我使用的更改 SVG 大小的内容。因此,当 SVG 改变大小时,出于某种原因我仍然无法让 CSS 过渡动画化。您可以在下面的 GIF 中查看动画失败。
我认为需要转换代码的元素是 SVG 本身,属于 areaSVG
类,因为它们是从 max-height: 18vh
变化的元素> 到 max-height: 9vh.
但是,当我向 .areaSVG
添加一些动画代码时,它不起作用,所以也许我错了。这是我尝试添加到失败的初始 SVG (.areaSVG
) 设置的转换代码:
-webkit-transition: max-height 1s;
-moz-transition: max-height 1s;
transition: max-height 1s;
几个月前,在另一位更有经验的编码员的帮助下,我添加了一个 javscript 函数,该函数在某个时候使 SVG 动画化。我们用JS调用了window.requestAnimationFrame(startAnimation)
,但是已经不行了。我评论了与此相关的部分,但如果您认为需要 JS 来制作动画,请随时 fork 代码笔并使用它。 一个合适的答案应该能让动画在 Safari、Chrome 和 Firefox 中运行。
这是您应该使用的最简单的最小化版本,因为它没有媒体查询(根据要求通过 @Eric N
:http://codepen.io/ihatecoding/pen/LREOPW
这是完整的代码笔,带有媒体查询:http://codepen.io/ihatecoding/pen/ALjKKz
第一部分(页面顶部)的选择器:
#indexFooter
.ey-col-svg
.areaSVG
第二部分的选择器(向下滚动 100 像素后):
#indexFooter.fixed
.ey-col-svg.fixed
.areaSVG.fixed
注意:当页面首次加载时,SVG 父级 (.ey-col-svg
) 和 SVG 本身 (.areaSVG
) 都是不可见的,设置 display:none
以避免给用户带来奇怪的体验。
以下是有关每个部分中重要元素的信息:
初始 CSS(第一部分)
/* 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;
}
接下来,JS 运行,然后显示元素(仍然在第一部分):
/* The SVG container*/
.ey-col-svg {
display: block;
}
/* The SVG*/
.areaSVG {
display: inline-block;
}
离开第一节后(此时页脚应该更小并固定)
/* The SVG when low on page*/
.areaSVG.fixed {
max-height: 9vh;
}
如果你想看,这里是Javascript
$(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
任何帮助将不胜感激!谢谢!
最佳答案
我这里有一个跨浏览器的解决方案:http://codepen.io/anon/pen/EgZzxo
它并不完美:更改宽度存在一些问题,但我相信您发布的问题已得到解答。要解决其他问题,您必须查看您的 css
以查看某些元素是否未更改 display
属性 - 这可能会扰乱您的过渡。固定宽度也应该有所帮助,因此它们不依赖于文本大小 - 当文本变小时它会改变,因此其他元素的位置也会随之改变。
您遇到的主要问题是 .ey-row-scale.fixed
有 display: inline-block
而 .ey-row.scale
没有。这是打破过渡的一件事。另一个是过渡必须在 svg
元素上定义,所以不是:
.indexAnimateLand {
}
我必须做的:
.indexAnimateLand svg {
}
然后就成功了。不确定具体原因,但可能是内联 svg 没有正确继承样式。
我还向文本元素添加了过渡效果,并且不得不理清您放置在那里的一些 !important
边距。
总的来说,代码可以在几个方面进行改进:
.fixed
时更容易看出有什么区别例如类font-size
不应在 vh
中定义,因为它与屏幕尺寸相关,并且可以使文字不可读!important
,或者更好的是,根本不要使用。通常,如果您解决了迫使您使用的问题,代码会更清晰!important
首先关于javascript - SVG 更改大小但不会在滚动过渡时设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39322082/
SO亲爱的 friend 们: 2014 年 3 月 18 日。我正在处理一种情况,在使用 ng-repeat 时,数组内的元素(我从 Json 字符串中获取)更改了原始顺序。 需要明确的是,数组中的
有很多问题询问如何在 JavaScript 单击处理程序中更改 div 的类,例如,此处:Change Div style onclick .我理解得很好(只需更改 .className),并且它有效
我从access导入了一个数据库到mysql,但其中一个表的列名“股数”带有空格,但我尝试更改、替换甚至删除列名,但失败了。任何人都可以帮助解决这一问题 String UpdateQuary = "U
我正在做一个随机的学校元素。 目前,我有一个包含两个 CSS 的页面。一种用于正常 View ,一种用于残障人士 View 。 此页面还包括两个按钮,它们将更改使用的样式表。 function c
我需要使用 javascript 更改 HTML 元素中的文本,但我不知道该怎么做。 ¿有什么帮助吗? 我把它定义成这样: Text I want to change. 我正在尝试这样做: docum
我在它自己的文件 nav_bar.shtml 中有一个主导航栏,每个其他页面都包含该导航栏。这个菜单栏是一个 jQuery 菜单栏(ApyCom 是销售这些导航栏的公司的名称)。导航栏上的元素如何确定
我正在摆弄我的代码,并开始想知道这个变化是否来自: if(array[index] == 0) 对此: if(!array[index] != 0) 可能会影响任何代码,或者它只是做同样的事情而我不需
我一直在想办法调整控制台窗口的大小。这是我正在使用的函数的代码: #include #include #define WIDTH 70 #define HEIGHT 35 HANDLE wHnd;
我有很多情况会导致相同的消息框警报。 有没有比做几个 if 语句更简单/更好的解决方案? PRODUCTS BOX1 BOX2 BOX3
我有一个包含这些元素的 XELEMENT B Bob Petier 19310227 1 我想像这样转换前缀。 B Bob Pet
我使用 MySQL 5.6 遇到了这种情况: 此查询有效并返回预期结果: select * from some_table where a = 'b' and metadata->>"$.countr
我想知道是否有人知道可以检测 R 中日期列格式的任何中断的包或函数,即检测日期向量格式更改的位置,例如: 11/2/90 12/2/90 . . . 15/Feb/1990 16/Feb/1990 .
我希望能够在小部件显示后更改 GtkButton 的标签 char *ButtonStance == "Connect"; GtkWidget *EntryButton = gtk_button_ne
我正在使用 Altera DE2 FPGA 开发板并尝试使用 SD 卡端口和音频线路输出。我正在使用 VHDL 和 C 进行编程,但由于缺乏经验/知识,我在 C 部分遇到了困难。 目前,我可以从 SD
注意到这个链接后: http://www.newscientist.com/blogs/nstv/2010/12/best-videos-of-2010-progress-bar-illusion.h
我想知道在某些情况下,即使剧本任务已成功执行并且 ok=2,ansible 也会显示“changed=0”。使用 Rest API 和 uri 模块时会发生这种情况。我试图找到解释但没有成功。谁能告诉
这个问题已经有答案了: 已关闭12 年前。 Possible Duplicate: add buttons to push notification alert 是否可以在远程通知显示的警报框中指定有
当您的 TabBarController 中有超过 5 个 View Controller 时,系统会自动为您设置一个“更多” View 。是否可以更改此 View 中导航栏的颜色以匹配我正在使用的颜
如何更改.AndroidStudioBeta文件夹的位置,默认情况下,该文件夹位于Windows中的\ .. \ User \ .AndroidStudioBeta,而不会破坏任何内容? /编辑: 找
我目前正在尝试将更具功能性的编程风格应用于涉及低级(基于 LWJGL)GUI 开发的项目。显然,在这种情况下,需要携带很多状态,这在当前版本中是可变的。我的目标是最终拥有一个完全不可变的状态,以避免状
我是一名优秀的程序员,十分优秀!