2016-08-12 65 views
2

在用戶登錄時無法擴展具有內容的div,而不需要任何click函數來擴展div,文檔加載時應該自動擴展它。使用jQueryanimate方法,但我無法做到這一點

$(function(){ 
    $("#wish_card").animate({ 
     height: "200px" 
    }); 
}); 
+0

你綁定在頁面加載的數據?你也可以使用window.load函數 –

+0

YEs我綁定的數據,但真正的事情是,div應該在頁面加載後展開 –

+0

在asp.net中?然後在數據綁定 –

回答

2

您需要使用jQuery提供$(document).ready()方法。無論何時頁面被加載,這將啓動animate方法。

$(document).ready(function(){ 
    $("#wish_card").animate({ 
     height: "200px" 
    }); 
}); 

演示:JsBin

0
$(window).load(function() { 
     $("#wish_card").animate({ height: "200px" }); 
    }); 
+0

雖然這可能會回答這個問題,但請提供任何解釋,以確保人們瞭解此處發生的情況。 – Randy

+0

非常感謝這個建議,我會在回答時記住 –

0

可能,這將是非常有用的給你

我們通常使用

$("document").ready(function() { 
 
    // The DOM is ready! 
 
    // The rest of the code goes here 
 
    });

而且較短的版本是

$(function() { 
 
    // The DOM is ready! 
 
    // The rest of the code goes here 
 
    });

,這是最後的最佳實踐

(function($, window, document) { 
 

 
    // The $ is now locally scoped 
 

 
    // Listen for the jQuery ready event on the document 
 
    $(function() { 
 

 
    // The DOM is ready! 
 

 
    }); 
 

 
    // The rest of the code goes here! 
 

 
    }(window.jQuery, window, document)); 
 
    // The global jQuery object is passed as a parameter

0

嘗試了這一點:

$(function(){$("#wish_card").animate({ height: "200px" })(); 

供您參考:

Edited demo Fiddle

+0

小提琴的鏈接似乎不起作用。 –

+0

@SomenathSinha鏈接已更新。 – Princess

相關問題