2013-05-01 33 views
2

我想要創建一個測試對象,使用jQuery在頁面加載時從左側進入屏幕。如何通過jQuery轉換將對象從外部移動到屏幕上

我已經把:

<script type='text/javascript'> 
$('animtext').transition({ x: 200 }, 500, 'ease'); 
</script> 

<head>之前,和.animtext的CSS是:

.animtext { 
background-image:url('../render_01.jpg'); 
width:400px; 
height:400px; 
} 

但沒有任何反應。

任何人都可以告訴我怎麼才能簡單地獲得一個對象使用jQuery進行轉換嗎?

* *謝謝Wiley迴應。仍然沒有快樂,不知道我做錯了什麼!

我確實安裝了相關的.js文件。

代碼現在看起來像:

<html> 
<head> 
<link rel="stylesheet" href="test.css" /> 

<script type='text/javascript' src='js/jquery.transit.js'></script> 
<script type='text/javascript' src='js/customtransit.js'></script> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js">  

</script> 

<script> 

$(document).ready(function(){ 
$('.animtext').transition({ x: 200px }, 500, 'ease'); 
}); 

</script> 
</head> 

<body> 

<div class="animtext"></div> 

</body> 
</html> 

仍然沒有運氣...任何幫助感激地接受。

+0

你'包括或jquery.js''jquery.min.js'什麼地方? – 2013-05-01 15:30:43

+0

也許你可以這樣做:http://www.impressivewebs.com/css3-transitions-javascript/ – cortex 2013-05-01 15:37:10

+0

它不應該在''之前,而是在''或''之前。最好是後者。 – 2013-05-01 17:58:41

回答

1

如果animtext是一個類你缺少.爲類選擇

$('.animtext') 

而且包裝你的代碼的document.ready函數裏面,如果你把你的代碼「內部」頭

$(document).ready(function(){ // or $(function(){ which is shorthand for $(document).ready(function(){ 
    // your code yere 
}); 

另一種方法是把你的代碼中的結束</body> tag之前

+0

謝謝你有線 - 仍然有問題,使這項工作。 – annoyingnewbie 2013-05-01 16:40:24

+0

你需要在你的其他js文件之前導入jQuery,因爲它們很可能依賴於jQuery – 2013-05-01 17:51:56

+0

@ user2339879這裏有一個它工作正常的例子[FIDDLE](http://jsfiddle.net/GeADD/) – 2013-05-01 17:57:17

相關問題