2017-02-09 15 views
0

私のコードにbackstretchを追加します。私たちは、このHTMLページを開くとイメージを動的に変更したい

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


これはスクリプトです。しかし、それは言っている

Uncaught type error. $backstretch is not a function.

我々はそれを含めることができますか?または、画像を動的に変更する他の方法はありますか?

+0

なぜjqueryを複数回組み込んだのですか?他のjsファイルの一番上に一度だけ含めてください。 –

答えて

1

上記errorの実際の理由であるpluginを初期化した後に、scriptsが含まれています。ちょうどあなたがjquery-1.11.1.min.js複数回への参照が含まれていると同じファイルに複数の参照を含めないでください任意の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> 

前に、すべてのスクリプトを動かします。

また、これらの行は​​3210でjquery(".foo")である必要があります。いいえ.jqueryの後

+1

おかげでそれはうまく動いた – rajshree

+0

@rajshreeいつでも..ハッピーコーディング..それが助けられたら答えとしてマークしてください:) –

関連する問題