2011-06-13 73 views
2

我有以下腳本(from here)加載圖像並將其設置爲背景。它工作正常,但我需要更改添加多張照片才能成爲幻燈片?用jQuery/css淡化背景圖片?

的jQuery:

$(document).ready(function(){ 

    $.fn.smartBackgroundImage = function(url){ 
     var t = this; 
     //create an img so the browser will download the image: 
     $('<img />') 
     .attr('src', url) 
     .load(function(){ //attach onload to set background-image 
       t.each(function(){ 
       $(this).css('backgroundImage', 'url('+url+')'); 
       }); 
      }); 
     return this; 
    } 
    $('body').smartBackgroundImage('/static/images/temp-bg.jpg'); 

}); 

謝謝!

+3

沒有冒犯或什麼,但只是想一想。看來你知道如何在JS中編寫代碼,所以這不是問題。根據你需要發生的情況,從邏輯上考慮你的問題,然後根據你的具體情況考慮,然後根據實際的代碼進行思考。如果您一路上遇到問題,請提出*問題。類似的更廣泛的問題不僅限於狹窄的研究問題。祝你好運! :) – 2011-06-13 02:05:52

+0

沒有采取任何進攻:)這只是我在一個項目上遲到了。解決方案看起來很簡單:可能會放入一個循環,淡入圖像。 – Cris 2011-06-13 02:17:14

+1

在那裏。 :)記錄,'setInterval(time)'在這裏派上用場。只需設置間隔即可更改照片。 https://developer.mozilla.org/En/Window.setInterval – 2011-06-13 02:19:27

回答

0

將您的圖像合併到html中使用<li>標籤,並使用jquery格式化它們。所以稍後更容易改變它們。