Javascript 如何使文本svg动画在可见时启动?
我的页面上有3个部分`Javascript 如何使文本svg动画在可见时启动?,javascript,jquery,html,css,svg,Javascript,Jquery,Html,Css,Svg,我的页面上有3个部分` <a href="#" class="next-section">Next Section</a> <div class="section-content"> </div> </section> <section id="about"> <a href="#" class="prev-section">Previous Section</a>
<a href="#" class="next-section">Next Section</a>
<div class="section-content">
</div>
</section>
<section id="about">
<a href="#" class="prev-section">Previous Section</a>
<a href="#" class="next-section">Next Section</a>
<div class="section-content">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="480px" height="640px" viewBox="0 0 480 640" enable-background="new 0 0 480 640" xml:space="preserve">
<rect x="68.631" y="175.105" fill="none" width="350.877" height="113.158"/>
在第二部分中,我有一些svg,使用CSS设置动画,但我希望在svg可见时启动动画。我应该怎么做?您可以将一个“完整”函数传递给jQuery
animate()
。当动画完成时,将调用该complete函数。在该函数中,您可以向SVG中添加一个类来触发动画。请制作一个提琴,这样我们就更容易理解您的意思并帮助编写代码。。。但是滚动和svg动画在那里不起作用。。。在左上角的“下一部分”有一个按钮,可以使页面向下滚动。您是否尝试了jquery选择器(“:visible”)?它应该选择一个可见元素。。。您可能应该使用一些$(function(){})来测试元素的位置是否位于窗口顶部和底部之间……好的,我们将尝试一下。
</div>
</section>
<section id="services">
<a href="#" class="prev-section">Previous Section</a>
<div class="section-content">
</div>
</section>
jQuery.fn.extend({
scrollTo : function(speed, easing) {
return this.each(function() {
var targetOffset = $(this).offset().top;
$('html,body').animate({scrollTop: targetOffset}, speed, easing);
});
}
});
$('.next-section').click(function(e){
e.preventDefault();
var $this = $(this),
$next = $this.parent().next();
$next.scrollTo(150, 'linear');
});
$('.prev-section').click(function(e){
e.preventDefault();
var $this = $(this),
$prev = $this.parent().prev();
$prev.scrollTo(150, 'linear');
});