2013-09-23 39 views
0

有人可以建议我如何从左到右缓慢地发送这个图像? 我可以看到图像,我可以点击它去url,但它没有动画,只是马上出现? 感谢jQuery从左到右加载动画图像

<!DOCTYPE html> 
<html> 
<head> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> 
</script> 
<script> 
$("#lefttoright").animate({opacity: 0.25, left: "=250", 
height: "toggle" }, 5000, function() { // Animation complete. 
});}); 
</script> 
</head> 
<body> 
    <div id="lefttoright">  
    <a href="http://www.stackoverflow.com" title="go to link"> 
    <img src="/images/leftright.png" alt="news" width="150" height="75" /></a> 
    </div> 
</body> 
</html> 

回答

2

你需要用听者在DOM ready handler

$(function(){ 

    $("#lefttoright").animate({ opacity: 0.25, left: "250", height: "toggle" }, 5000, function() {  
     // Animation complete. 
    }); 
}); 

fiddle code在这里

<div id="lefttoright"> <a href="http://www.stackoverflow.com" title="go to link"> 
    <img src="https://www.google.com/images/srpr/logo4w.png" alt="news" width="150" height="75" /></a> 
</div> 

var left = $(window).width() - $('#lefttoright').offset().left; 

$("#lefttoright").animate({ 
    opacity: 0.25, 
    left: left, 
}, 5000, function() { 
    // Animation complete. 
}); 


#lefttoright { 
    width: 200px; 
    height: 200px; 
    position: absolute; 
    background: yellow; 
} 
+1

打我给它笑 – mcgrailm

+0

布里尔它做的事情,它显示了完整的图像然后从下往上吃,然后吃掉,我怎么能从左边爬过来,然后停下来,比如说200px之后;?谢谢 – Dillon

+0

你可以创建一个小提琴吗? – karthikr