0

哪位好心人可以建议我如何将这张图片从左向右缓慢发送?我可以看到图像,我可以单击它转到 url,但它没有动画,只是立即出现?谢谢

 <!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>
4

1 回答 1

2

您需要将侦听器包装在DOM 就绪处理程序中

$(function(){

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

小提琴代码在这里

<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;
}
于 2013-09-23T15:17:37.143 回答