2012-11-20 174 views
2

我想在頁面加載時添加一些動畫。我嘗試了幾次,但沒有成功。你能幫我用jquery破解嗎?在頁面加載時添加動畫(從左/右滑動等)

HTML & jQuery的部分:

<div class="MainPozEstate"><a href=""><img src="assets/img/mrk-sng.png" alt="Acarkent Markavilla"/></a></div> 
    <script type="text/javascript"> 
     jQuery(document).ready(function($) { 
      $(".MainPozEstate a").mouseover(function() { 
       $(this).children("img").stop(true, true).animate({ 
        opacity: 0.6 
       }, 200, "swing", function() { 
        $(this).animate({ 
         opacity: 1 
        }, 400); 
       }); 
      }); 
     }); 
    </script> 

CSS線:

.MainPozEstate {float:left;width:980px;margin:0px auto;padding-top:30px;text-align:center;} 
.MainPozEstate img {border:none;margin:0px auto;} 

感謝。

+0

它看起來像你的動畫觸發'mouseover',而不是在頁面加載時。這是打算嗎? – greener

回答

1

如果你想添加另一個效果,那麼也許做另一個電話。 http://jsfiddle.net/fedmich/w8HzE/2/

jQuery(document).ready(function($) { 
    $(".MainPozEstate a").mouseover(function() { 
     $(this).children("img").stop(true, true).animate({ 
      opacity: 0.6 
     }, 200, "swing", function() { 
      $(this).animate({ 
       opacity: 1 
      }, 400); 
     }); 
    }); 

    // 
}); 

jQuery(document).ready(function($) { 
    //do your other effects here or just trigger/call mouseover if you want. 
    $(".MainPozEstate a").mouseover(); 
}); 

我覺得你的代碼工作,http://jsfiddle.net/fedmich/w8HzE/

+0

是的,我添加了它。但我想爲MainPozEstate div圖像添加另一個動畫效果。當你在瀏覽器上打開該頁面時,該圖像應該從左側開始滑動,然後在5秒後停止動畫。 –