2014-10-12 22 views
0

嗨我有這種代碼可以提供類型書寫效果。但是thigs是我想要動畫只有當用戶向下滾動到這個div時才能運行。你們能幫忙嗎?由於當達到特定分區時啓動jquery動畫

<script> 
 
\t 
 
    $(function(){ 
 

 
     $("#typed").typed({ 
 
      strings: ["oru exp", "Oru expertise", '"Our expertise Graphic Designer will create the template based \n on your company activity and will provide with a proffesional \n and ergonic design to your website."'], 
 
      typeSpeed: 30, 
 
      backDelay: 500, 
 
      loop: false, 
 
      // defaults to false for infinite loop 
 
      loopCount: false, 
 
      callback: function(){ foo(); }, 
 
      resetCallback: function() { newTyped(); } 
 
     }); 
 

 
     $(".reset").click(function(){ 
 
      $("#typed").typed('reset'); 
 
     }); 
 

 
    }); 
 

 
    function newTyped(){ /* A new typed object */ } 
 

 
    function foo(){ console.log("Callback"); } 
 

 
    
 
    </script>

這裏是HTML:有關獲取一定的高度,然後播放動畫

<div class="wrap"> 
    <div class="type-wrap"> 
    <span id="typed" style="white-space:pre;"></span> 
    </div> 
</div> 
+0

請發佈html也 – doniyor 2014-10-12 06:22:28

+0

非常感謝。所以你有任何想法如何做到這一點? – ggguu 2014-10-12 06:32:07

+0

你有沒有你不想要的工作例子? – doniyor 2014-10-12 06:36:52

回答

1
$(window).scroll(function(){ 
    var height = $(window).scrollTop(); 
    if(height > 400){ 
     // $('#your_htmlelement').typed(); 
    }else{ 
     // $('#your_htmlelement').typed('reset'); 
    } 
}); 

jsFiddle

什麼?

+0

@dcc哈哈謝謝。 – doniyor 2014-10-12 06:43:58

+1

肯定的事情。即將發佈非常相似的答案,但不想複製你。 – davidcondrey 2014-10-12 06:44:26

+0

實際上這是一個水平導航。所以我用寬度替換了高度,但現在動畫不起作用。沒有錯誤雖然.. – ggguu 2014-10-12 06:53:17