2017-02-09 110 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任何时候..快乐编码..如果它帮助..标记为答案.. :) –

相关问题