0

I've been scratching my head for a few days on this now. I have a site running a jcarousellite slider on the home page. On another page of the site I want the side nav to be sticky (i.e. be position: relative; whilst scrolling until it reaches the top of the page and then position: fixed; thereafter).

I have the following code being called in:

//jQuery Functions

$(document).ready(function(){


//JCarouselLite
$(function() {
$("#mainSlider").jCarouselLite({
    btnNext: "#sliderBtnNext",
    btnPrev: "#sliderBtnPrev",
    visible: 1,
    auto: 6000,
    speed: 1000
    });
});


//Sticky Side Nav
var stickerTop = parseInt($('#sticker').offset().top);
$(window).scroll(function() {
    $("#sticker").css((parseInt($(window).scrollTop()) + parseInt($("#sticker").css('margin-top')) > stickerTop) ? {
        position: 'fixed',
        top: '0px'
    } : {
        position: 'relative'
    });
});

});

In its current format, the sticky sidenav code is working fine, but jcarousellite is not. If I remove the sticky sidenav code, then jcarousellite works fine.

I'm sure this is going to be something simple like a syntax error but I just cant seem to solve it.

Any help much appreciated.

4

1 回答 1

0

使用 $ 作为文档准备好的函数参数

 //jQuery Functions

 jQuery(document).ready(function($){


 //JCarouselLite
 $(function() {
  $("#mainSlider").jCarouselLite({
   btnNext: "#sliderBtnNext",
   btnPrev: "#sliderBtnPrev",
   visible: 1,
   auto: 6000,
   speed: 1000
 });
});


//Sticky Side Nav
var stickerTop = parseInt($('#sticker').offset().top);
$(window).scroll(function() {
$("#sticker").css((parseInt($(window).scrollTop()) +      parseInt($("#sticker").css('margin-top')) > stickerTop) ? {
     position: 'fixed',
     top: '0px'
  } : {
    position: 'relative'
  });
 });

 });
于 2013-08-28T16:36:34.407 回答