2014-04-21 24 views
-1

我想飛行文本。我正在使用的代碼: -使用jQuery將文本飛到特定的div

var cart = jQuery('.flying-shopping-cart'); 
    var texttodrag = jQuery(this).html(); 
    if (texttodrag) { 
     var textclone = texttodrag.clone() 
      .offset({ 
      top: texttodrag.offset().top, 
      left: texttodrag.offset().left 
     }) 
      .css({ 
      'opacity': '0.5', 
       'position': 'absolute', 
       'height': '150px', 
       'width': '150px', 
       'z-index': '100' 
     }) 
      .appendTo(jQuery('body')) 
      .animate({ 
      'top': cart.offset().top + 10, 
       'left': cart.offset().left + 10, 
       'width': 75, 
       'height': 75 
     }, 1000, 'easeInOutExpo'); 

     setTimeout(function() { 
      cart.effect("shake", { 
       times: 2 
      }, 200); 
     }, 1500); 

     textclone.animate({ 
      'width': 0, 
       'height': 0 
     }, function() { 
      jQuery(this).detach() 
     }); 
    } 

但它顯示TypeError: texttodrag.clone is not a function。它適用於圖像,但適用於文本。請幫我

+0

您想先解決控制檯錯誤。 –

+0

請提供HTML也或jsfiddle –

+0

我沒有看到在您的代碼中使用變量'imgtodrag'..嘗試創建一個小提琴,所以我們可以找到它。我也懷疑'imgtodrag'不是一個jQuery變量..所以嘗試像'$(imgtodrag).clone()' – Praveen

回答

0

問題得到解決: -

function flyToCart(flyer, flyingTo, filterId , callBack) { 
// try { 
    jQuery(".currently").fadeIn(3000); 
    var $jqfunc = jQuery(this); 
    var divider = 3; 
    flyerClone = jQuery.trim(flyerClone); 
    var flyerClone = jQuery(flyer).clone(); 
    jQuery(flyerClone).css({ 
     'font-size': '14px', 
     'font-family':'Arial', 
     'background':'white', 
     'width':'150px', 
     'height':'150px', 
     position: 'absolute', 
     'display':'block', 
     'border':'1px solid #cccccc', 
     top: jQuery('#'+filterId).offset().top + "px", 
     left: jQuery('#'+filterId).offset().left + "px", 
     opacity: 1, 
     'z-index': 1000 
    }); 
    jQuery('body').append(jQuery(flyerClone)); 
    if(jQuery(flyingTo)) { 
     var gotoX = jQuery(flyingTo).offset().left + 10; 
     var gotoY = jQuery(flyingTo).offset().top + 10; 
     jQuery(flyerClone).animate({ 
      opacity: 1, 
      left: gotoX, 
      top: gotoY, 
      width: 150, 
      height: 10, 
      padding: '5 10 10 10' 
     }, 1000, 
     function() {; 
      jQuery(flyingTo).fadeOut('slowly', function() { 
       jQuery(flyingTo).fadeIn('slowly', function() { 
        jQuery(flyerClone).fadeOut('slowly', function() { 
         jQuery(flyerClone).remove(); 
         if(callBack != null) { 
          callBack.apply($jqfunc); 
         } 
        }); 
       }); 
      }); 
     }); 
    }  
} 

我用這個劇本,希望這將有助於其他提供飛行影響。

1

使用length屬性來檢查HTML有:

if (texttodrag.length) { 
+0

現在還它顯示類型錯誤:texttodrag.clone不是一個函數 \t VAR textclone = texttodrag.clone ()error –

+0

是否可以將文本飛到特定的div –

+0

飛?你的意思是從一個HTML標籤到其他HTML標籤,如果是這樣你可以使用appendTo()方法 –