user1142121
user1142121

Reputation: 49

Calling same Jquery file many times

I have multiple instances where I use jquery on my site (like an image slider and navigation) but they will not work if I do not place the jquery call multiple times.

E.g. the 2 snippets below won't work unless I call the script twice. Please help. (There are more jquery calls on my page as well calling different libraries) Can't I just call the latest library once and be done with it? I tried and doesn't work.

<!--menu -->
<script type="text/javascript" src="js/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/newnav.css" />
<script type="text/javascript" src="js/navdoublecolumn.js"></script>
<script>
<!--
ddmegamenu.docinit({
    menuid:'solidmenu',
    dur:0, 
    easing:'easeInOutCirc' //<--no comma after last setting
})
// -->
</script>



<!-- slide -->
<script type="text/javascript" src="js/jquery.min.js"></script>
<script src="js/jquery.tabSlideOut.v1.3.js"></script>

<script type="text/javascript">
$(function(){
    $('.slideout1').tabSlideOut({
        tabHandle: '.slideouthandle1',             //class of the element that will become your tab
        pathToTabImage: 'images/slideouttab_chat.jpg',//path to the image for the tab //Optionally can be set using css
        imageHeight: '150px',                     //height of tab image           //Optionally can be set using css
        imageWidth: '40px',                       //width of tab image            //Optionally can be set using css
        tabLocation: 'left',                      //side of screen where tab lives, top, right, bottom, or left
        speed: 200,                               //speed of animation
        action: 'click',                          //options: 'click' or 'hover', action to trigger animation
        topPos: '215px',                          //position from the top/ use if tabLocation is left or right
        leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
        fixedPosition: true                       //options: true makes it stick(fixed position) on scroll
    });

});
</script>

Upvotes: 0

Views: 192

Answers (2)

seb
seb

Reputation: 4096

I expect something in navdoublecolumn.js is overwriting or otherwise breaking jQuery functionality. By including jQuery a second time, you are redefining the methods / variables and therefore restoring functionality that navdoublecolumn.js has broken.

You may get a clue to what is breaking by looking at the javascript console error output you get when you remove the second jQuery inclusion.

Upvotes: 1

zb&#39;
zb&#39;

Reputation: 8059

As you using jQuery.noconflict() use this:

jQuery(function($){
    $('.slideout1').tabSlideOut({
        tabHandle: '.slideouthandle1',             //class of the element that will become your tab
        pathToTabImage: 'images/slideouttab_chat.jpg',//path to the image for the tab //Optionally can be set using css
        imageHeight: '150px',                     //height of tab image           //Optionally can be set using css
        imageWidth: '40px',                       //width of tab image            //Optionally can be set using css
        tabLocation: 'left',                      //side of screen where tab lives, top, right, bottom, or left
        speed: 200,                               //speed of animation
        action: 'click',                          //options: 'click' or 'hover', action to trigger animation
        topPos: '215px',                          //position from the top/ use if tabLocation is left or right
        leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
        fixedPosition: true                       //options: true makes it stick(fixed position) on scroll
    });

});

Upvotes: 0

Related Questions