0

I'm having trouble with this bit of code due to changes in CSS margins that need to be accounted for. I want to change the var $offset in the serialScroll plugin by adding the $margins from the if/else in the .keybind function. I'm a novice with javascript and I'm not sure how to do this properly.

Here is my code:

 jQuery(function( $ )                                   
{                           
    var $nav = $('#slideshow li');  
    var $margins = 0;
    var $offset = (-220 + $margins);    //this offsets the elements 

$('#maincontent').serialScroll(             //serialscroll
    {
    items:'li',
    prev:'.leftArrow, div.logo#logo',
    next:'.rightArrow',
    offset:$offset,
    start:0,
    duration:500,
    force:false,
    stop:true,                          
    easing:'swing',
    navigation:$nav,        
    onBefore:function(e,el,$p,$i,pos)
        {
        $nav.removeAttr('id'),     //this removes id from old element
        $nav.eq(pos).attr("id","yourit"),//this adds id to new element
        $nav.removeClass('select'),    //this removes class from old element
        $nav.eq(pos).addClass('select'); //this adds class to new element
        },

/*///////////////////////////////////////////////////////
                keyboard binds
*////////////////////////////////////////////////////////

var $pane = $('#maincontent')               
$(document).keydown(function(e) //keyboard bind 
    {
    if( e.keyCode == 39 )     //right (->)
        {   
        if 
            ($('.selectstyle').hasClass("selectstyle"))
                {
                $margins = -180; //i want to get this value and add it to my $offset var
                $(".selectstyle" ).removeClass( "selectstyle", 200);
                $pane.trigger('next');
                return false;
                }               
        else
                ($(".select" ).hasClass("select"))
                {
                $margins = 0; //ditto with this var if true
                $(".select" ).removeClass( "select", 200);
                $pane.trigger('next');
                return false;
                }
        }
    });

1 Answers1

0

You declared $margins within a function and thus you made it a local variable. If you want other functions to use it, you need to declare it outside the function and make it global.

Try declaring var $margins = 0; next to where you declared $offset at the top. Then delete the word var next to $margins from within the if-else statement.

Hope it will help.

Mahm00d
  • 3,881
  • 8
  • 44
  • 83
Shlo
  • 1,036
  • 2
  • 10
  • 23
  • Hi Shlo, I tried what you suggested but it still doesn't seem to work. I updated the code above to what you suggested. Can you spot any mistake? – user1317417 Apr 21 '12 at 21:32
  • maybe because you forget to place ";" at the end of these lines? – Shlo Apr 22 '12 at 06:49
  • Hi, I've entered the semi-colons but still no joy. The value seems to be stuck on zero no matter what I do. – user1317417 Apr 22 '12 at 17:01