Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将SVG转换为jQuery函数_Javascript_Jquery_Svg - Fatal编程技术网

Javascript 将SVG转换为jQuery函数

Javascript 将SVG转换为jQuery函数,javascript,jquery,svg,Javascript,Jquery,Svg,我有一个svg <svg class="svg_el" viewbox="0 0 100 100" preserveaspectratio="none"> <path class="overlay_path"> <animate attributeName="d" values="M 0 0 V 0 C 50 0 50 0 100 0 V 0 H 0; M 0 25 V 25 C 50 15 50 60 1

我有一个svg

<svg class="svg_el" viewbox="0 0 100 100" preserveaspectratio="none">
  <path class="overlay_path">
    <animate attributeName="d" values="M 0 0 V 0 C 50 0 50 0 100 0 V 0 H 0;                         M 0 25 V 25 C 50 15 50 60 100 50 V 0 H 0;                         M 0 50 V 50 C 50 50 50 85 100 80 V 0 H 0;                         M 0 100 V 100 C 50 100 50 100 100 100 V 0 H 0" dur="0.4s" fill="freeze" repeatCount="1"></animate>
    <animate attributeName="d" values="M 0 0 C 50 0 50 0 100 0 V 100 H 0;                         M 0 25 C 50 15 50 60 100 50 V 100 H 0;                         M 0 50 C 50 50 50 85 100 80 V 100 H 0;                         M 0 100 C 50 100 50 100 100 100 V 100 H 0" dur="0.4s" begin="0.73s" fill="freeze" repeatCount="1"></animate>
  </path>
  <path class="overlay_path">
    <animate attributeName="d" values="M 0 0 V 0 C 50 0 50 0 100 0 V 0 H 0;                         M 0 25 V 25 C 50 15 50 60 100 50 V 0 H 0;                         M 0 50 V 50 C 50 50 50 85 100 80 V 0 H 0;                         M 0 100 V 100 C 50 100 50 100 100 100 V 0 H 0" dur="0.4s" begin="0.1s" fill="freeze" repeatCount="1"></animate>
    <animate attributeName="d" values="M 0 0 C 50 0 50 0 100 0 V 100 H 0;                         M 0 25 C 50 15 50 60 100 50 V 100 H 0;                         M 0 50 C 50 50 50 85 100 80 V 100 H 0;                         M 0 100 C 50 100 50 100 100 100 V 100 H 0" dur="0.4s" begin="0.63s" fill="freeze" repeatCount="1"></animate>
  </path>
  <path class="overlay_path">
    <animate attributeName="d" values="M 0 0 V 0 C 50 0 50 0 100 0 V 0 H 0;                         M 0 25 V 25 C 50 15 50 60 100 50 V 0 H 0;                         M 0 50 V 50 C 50 50 50 85 100 80 V 0 H 0;                         M 0 100 V 100 C 50 100 50 100 100 100 V 0 H 0" dur="0.4s" begin="0.2s" fill="freeze" repeatCount="1"></animate>
    <animate attributeName="d" values="M 0 0 C 50 0 50 0 100 0 V 100 H 0;                         M 0 25 C 50 15 50 60 100 50 V 100 H 0;                         M 0 50 C 50 50 50 85 100 80 V 100 H 0;                         M 0 100 C 50 100 50 100 100 100 V 100 H 0" dur="0.4s" begin="0.53s" fill="freeze" repeatCount="1"></animate>
  </path>
</svg>

即使间隔为10(甚至1),暂停也会在完全不同的时间发生,似乎无法在正确的时刻捕捉到它,因此我认为最好的办法是将svg转换为jQuery,以便更好地控制它,有没有一种简单的方法可以做到这一点,或者我必须学习如何做到这一点?

如果我正确理解您想要实现的目标,每个路径的第一个动画应该立即运行,第二个动画只有在新页面加载后才运行。如果是这种情况,您可以显式地执行此操作

为第二个动画中最早的动画设置一个
id=“reveal”
begin=“unfinite”
,并以
$('#reveal')[0]开始。然后,可以使用相对开始时间开始其他两个动画:
begin=“leaver.begin+0.1s”


非常感谢,我会尝试一下,让你知道它的进展。不客气,但这是OP建议的编辑。我只是批准了它。
  $('.the_box').removeClass('loaded');
  $('.ccs').load('/wordpress/wp-content/themes/Tsunami-Waves-PHP/img/waves.svg', function() {
    var svgDoc = $('.ccs svg');
    var animWatch = setInterval(function() {
      if (svgDoc[0].getCurrentTime() > 0.56 && !($('.the_box').hasClass('loaded'))) {
        svgDoc[0].pauseAnimations();
        console.log(svgDoc[0].getCurrentTime());
      } else if (svgDoc[0].getCurrentTime() > 0.56 && $('.the_box').hasClass('loaded')) {
        svgDoc[0].unpauseAnimations();
        $('.the_box').siblings('.slider-transition').html($('.the_box').html());
        $('.slider-transition').children('.slider-transition').unwrap();
        $('video').trigger('play');
        clearInterval(animWatch);
      }
    }, 10);
  });
  // $('#holder').load(function(){ var imgcount = $('#holder img').length; $('#holder img').load(function(){ imgcount--; if (imgcount == 0) { /* now they're all loaded, let's display them! */ } }); });
  $('.the_box').load(href + ' .slider-transition', function() {
    var svgDoc = $('.ccs svg');
    $(this).addClass('loaded');
    $('.woocommerce-product-gallery').each(function() {
      $(this).wc_product_gallery();
    });
    slideShowInit();
    initParalax();
  });
<svg class="svg_el" viewbox="0 0 100 100" preserveaspectratio="none">
  <path class="overlay_path">
    <animate attributeName="d" values="..." dur="0.4s" fill="freeze"></animate>
    <animate attributeName="d" values="...." dur="0.4s" begin="reveal.begin+0.2s" fill="freeze"></animate>
  </path>
  <path class="overlay_path">
    <animate attributeName="d" values="..." dur="0.4s" begin="0.1s" fill="freeze"></animate>
    <animate attributeName="d" values="" dur="0.4s" begin="reveal.begin+0.1s" fill="freeze"></animate>
  </path>
  <path class="overlay_path">
    <animate attributeName="d" values="" dur="0.4s" begin="0.2s" fill="freeze"></animate>
    <animate id="reveal" attributeName="d" values="..." dur="0.4s" begin="indefinite" fill="freeze"></animate>
  </path>
</svg>
  $('.the_box').removeClass('loaded');
  var svgLoad = $.Deferred(), sliderLoad = $.Deferred();
  // first animations start immediatly after svg load
  $('.ccs').load('/wordpress/wp-content/themes/Tsunami-Waves-PHP/img/waves.svg', svgLoad.resolve);
  $('.the_box').load(href + ' .slider-transition', sliderLoad.resolve);
  // wait for both load events
  $.when(svgLoad, sliderLoad).then(function() {
    var svgDoc = $('.ccs svg');
    // delay start time of second animations if load is earlier than 0.53s
    var startTime = Math.max(0.53, svgDoc[0].getCurrentTime());
    var reveal = $('#reveal');
    // link DOM change and video play to animation beginEvent
    reveal.on('beginEvent', function () {
        $('.the_box').siblings('.slider-transition').html($('.the_box').html());
        $('.slider-transition').children('.slider-transition').unwrap();
        $('video').trigger('play');
    });
    reveal[0].beginElementAt(startTime);
    $(this).addClass('loaded');
    $('.woocommerce-product-gallery').each(function() {
      $(this).wc_product_gallery();
    });
    slideShowInit();
    initParalax();
  });