2011-11-22 7 views
6

पहले एक बार देख ले:.animate

enter image description here

बिल्ली एक वक्र में एक्स पर ले जाने की जरूरत है। (तीर देखें)

जब बिल्ली एक्स को हिट करती है, तो उसे 10 सेकंड रहना चाहिए, और उसके बाद बिल्ली को वक्र में फिर से वापस जाना चाहिए, और दोहराना चाहिए।

मैं इस कोड के साथ इसे करने की कोशिश:

function curve() { 
    $('#cat').delay(10000).animate({top: '-=20',left: '-=20'}, 500, function() { 
     $('#cat').delay(10000).animate({top: '+=20', left: '+=20'}, 500, function() { 
      curve(); 
     }); 
    }); 
} 

curve(); 

लेकिन बिल्ली इस तरह बढ़ रहा है:

enter image description here

वहाँ एक रास्ता बिल्ली वक्र के इस प्रकार में स्थानांतरित करने के लिए प्राप्त करने के लिए है ?

+0

http://stackoverflow.com/questions/2240052/how-would-you-animate-something-so-that-it- निम्न-ए-वक्र – RightSaidFred

+0

वाईयूआई घुमावदार एनिमेशन के लिए भी समर्थन प्रदान करता है। http://developer.yahoo.com/yui/examples/animation/control.html –

उत्तर

1

आप, कि प्राप्त करने के लिए आसान एक यौगिक आंदोलन करके उपयोग कर सकते हैं:

function curve() { 
    $('#cat').delay(10000).animate({top: "+=20px", left: "+=20px"}, { 
     duration: 500, 
     specialEasing: {top: 'easeOutQuad', left: 'easeInQuad'}, 
     complete: function() { 
     $('#cat').animate({top: "-=20px", left: "+=20px"}, { 
      duration: 500, 
      specialEasing: {top: 'easeInQuad', left: 'easeOutQuad'}, 
      complete: function() { 
      // repeat the other way around. 
      }}); 
     } 
    }); 
} 

यह jQuery 1.4 के बाद से काम करता है, के अनुसार jQuery docs और उल्लेख किए गए easings को jQuery UI की आवश्यकता होती है (लेकिन केवल Effect Core मॉड्यूल)। प्रत्येक .animate() कॉल पूर्ण सर्कल पथ की एक चौथाई के लिए कॉल करता है, और easeInQuad बनाम easeOutQuad बनाता है, पथ सीधे नई स्थिति के बजाय एक परिपत्र पथ की तरह दिखता है।

+0

हाय matehat! मुझे यह त्रुटि मेरी त्रुटि कंसोल में मिली: त्रुटि: f.easing [e.animatedProperties [this.prop]] कोई फ़ंक्शन नहीं है स्रोत फ़ाइल: फ़ाइल: /// सी:/डॉक्यूमेंट% 20und% 20इंस्टेलंगेन/प्रशासक/डेस्कटॉप/tyler/js/js/jquery-1.6.4.min.js रेखा: 4 – bernte

+0

आपको शायद jQuery UI (केवल प्रभाव कोर भाग) को शामिल करने की आवश्यकता है, यह [फ़ाइल] (https://github.com/jquery/ विशेष रूप से jquery-ui/blob/मास्टर/ui/jquery.effects.core.js)। – matehat

0

एक छोटे से स्क्रिप्ट सिर्फ सीधी रेखा में गमन नहीं एनीमेशन के लिए, नहीं है, pathAnimator बुलाया