2017-02-09 78 views
0

我想在我的代碼中添加backstretch
這是腳本:

<script> 
    // To attach Backstrech as the body's background 
    jquery.backstretch("/form-3/assets/img/backgrounds/1.jpg"); 

    // You may also attach Backstretch to a block-level element 
    jquery.(".foo").backstretch("/form-3/assets/img/backgrounds/1.jpg"); 

    // If your element defines a background image with CSS, you can omit the argement altogether 
    //$(".foo").backstretch(); 

    // Or, to start a slideshow, just pass in an array of images 
    jquery.(".foo").backstretch([ 
     "/form-3/assets/img/backgrounds/1.jpg", 
     "/form-3/assets/img/backgrounds/2.jpg", 
     "/form-3/assets/img/backgrounds/[email protected]"  
    ], {duration: 4000}); 

</script> 

//I have included the scripts here 
<script src="/form-3/assets/js/jquery-1.11.1.min.js"></script> 
<script src="/form-3/assets/js/jquery-1.11.1.js"></script> 
<script src="/form-3/assets/bootstrap/js/bootstrap.min.js"></script> 
<script src="/form-3/assets/js/jquery.backstretch.min.js"></script> 

<script src="/form-3/assets/js/jquery.backstretch.js"></script> 
<script src="/form-3/assets/js/scripts.js"></script> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script> 

我要動態地改變圖像爲我們打開該HTML頁面。但這是說

Uncaught type error. $backstretch is not a function.

我們如何包括它?或者有沒有其他方法可以動態改變圖片?

+0

爲什麼你多次包含jquery?在其他js文件的頂部只包含一次。 –

回答

1

初始化plugin後,您即包含scripts,這是上述error的實際原因。就在移動之前的任何js

<script src="/form-3/assets/js/jquery-1.11.1.min.js"></script> 
<script src="/form-3/assets/bootstrap/js/bootstrap.min.js"></script> 
<script src="/form-3/assets/js/jquery.backstretch.min.js"></script> 
<script src="/form-3/assets/js/jquery.backstretch.js"></script> 
<script src="/form-3/assets/js/scripts.js"></script> 

<script> 
    // To attach Backstrech as the body's background 
    jquery.backstretch("/form-3/assets/img/backgrounds/1.jpg"); 

    // You may also attach Backstretch to a block-level element 
    jquery.(".foo").backstretch("/form-3/assets/img/backgrounds/1.jpg"); 

    // If your element defines a background image with CSS, you can omit the argement altogether 
    //$(".foo").backstretch(); 

    // Or, to start a slideshow, just pass in an array of images 
    jquery.(".foo").backstretch([ 
    "/form-3/assets/img/backgrounds/1.jpg", 
    "/form-3/assets/img/backgrounds/2.jpg", 
    "/form-3/assets/img/backgrounds/[email protected]"  
    ], {duration: 4000}); 

</script> 

所有的腳本不包括多個引用同一文件中已包含參考jquery-1.11.1.min.js多次。

另外我覺得這些行​​3210必須是jquery(".foo")。否.jquery

+1

感謝它工作得很好 – rajshree

+0

@rajshree任何時候..快樂編碼..如果它幫助..標記爲答案.. :) –

相關問題