2009-11-16 47 views

回答

2

The MooTools docs for Element.Style應該能夠爲你解答這個問題。

+0

我看到了這mootools的代碼http://stackoverflow.com/questions/913173/body-background-image-change-with-fade-effect-mootools $(document.body的).setStyle('背景-image','url('+ pBackground +')'); 但我不知道如何應用它... – efoc 2009-11-16 15:36:56

+0

也許舊的文檔顯示了一個例子,但最新的文檔沒有顯示設置背景圖像的例子 – 2013-08-09 07:22:22

7

例如,在頁面加載:

<div id="yourElement"></div> 

<script type="text/javascript"> 
window.addEvent('domready', function() { 
    $('yourElement').setStyle('background-image', 'url(path/to/your/image)'); 
}); 
</script> 
1
window.addEvents({ 
    // fire when the DOM is loaded 
    domready: function(){ 
    // path to the image 
    var pathToBackgroundImage = '/path/to/the/image.jpg'; 
    // set the background-image 
    $(document.body).setStyle('background-image','url(' + pathToBackgroundImage + ')'); 
    } 
}); 

你需要,如果你決定你想淡入圖像採取顯著不同的方法。

+0

謝謝。任何演示爲背景圖像淡入效果? 我在http://devthought.com/wp-content/projects/mootools/barackslideshow/Demo/ 看到了這是否有可能使它改變背景圖片? – efoc 2009-11-17 05:17:45

+0

這並不容易。沒有嚴格改變文件的背景圖像。您需要創建一個人造背景容器(一個絕對定位的div,位於正文內容的其餘部分下方),並在該元素上應用腳本而不是Body本身。我從來沒有見過這樣做以前正確。 – 2009-11-20 10:20:20