views:

31

answers:

1

Try to find a global function, to get and to put the backgroundPosition-values, but I feel a bit confused. Here is the function:

  function global_backgroundPosition_Menu(num){
        $('#Navigation_1')
            .css({
              backgroundPosition: num + "px 0"
                })
    }

/////////////////// An here I want to call and put the function:

if ($('#Navigation_1 li.leistungen.active').length != 0){

        global_backgroundPosition_Menu();
        $('#Navigation_1')
        .css({
          backgroundImage: "url(images/background/menu_highlight_hg.png)",
          backgroundRepeat: "no-repeat",
            })
        .animate({
          backgroundPosition: "30px 0"
            })
        global_backgroundPosition_Menu(30)
      };
A: 

its a simple jQuery command i would not make a funktion just for this.

but you have to use it like this.

$('#Navigation_1').css('background-position', num + 'px 0')
or
$('#Navigation_1').css({background-position: num + 'px 0'})

your function could look like that:

this.bghelper = function(element, setter){
if ($(element).length){
  element = $(element)
  if (setter) {
    element.css('background-position', setter + 'px 0') // sets the bg ig settter is set
  }else{
    return element.css('background-position') // returns the bg position if setter i not set
  }
}else{
  return false
}
}

bghelper('#Navigation_1', 20) //call the function to set the bg position

bghelper('#Navigation_1') //call the function to get the bg position

-- meo yesterday


---> Thanks meo for your answer, unfortunately your answer disappeared. So i repeat it her.


I will use this procedere, after a new page is load. But there, the setter is :

0%  0% 

and not something like

20px 0

Has anyone an idea …

andi