开发者

Declaring jQuery functions all over again to set different values on ie7. Any other way to do this?

开发者 https://www.devze.com 2022-12-17 09:41 出处:网络
Well i have a scrolling plugin that i\'m using to move divs when i click nav anchors. There are two different settings, which i already didn\'t want to happen, but i had too since i didn\'t know a way

Well i have a scrolling plugin that i'm using to move divs when i click nav anchors. There are two different settings, which i already didn't want to happen, but i had too since i didn't know a way around this:

Look:

var jump=function(e)
{
//the plugin code...
  scrollTop: $(target).offset().top - 110
}

and another one with a different offset subtract number

var jump=function(e)
{
//the plugin code...
  scrollTop: $(target).off开发者_JS百科set().top - 315
}

Than i call them by using this :

$('li.sidebarLi a').bind("click", jump2);
$('li.yearsLi a').bind("click", jump);
return false;

What happened with ie7 is that it, for some freaking reason beyond imagination the final position is totally different. So i had to create an if on html for ie7 and call those functions again with different values (for both 110, and 315).

So the end result for ie7 users, is 2 useless function calling and 2 usefull. What i wanted was to have an way to do that without calling all that again, maybe a dynamic way to change that value if ie7. And if someone knew a way to do this without 2 functions, better, it would have to have to check to see if its sidebar or years nav and than set the value to scroll.

Hope someone can help me out with this one. Cheers.


Try:

scrollTop: $(target).offset().top - ($.browser.msie && parseInt($.browser.version)==7? 315: 110)

That said, it's unlikely that this issue is due to IE7 alone - I'd suggest trying to treat the underlying symptom than to superficially throw conditionals about

0

精彩评论

暂无评论...
验证码 换一张
取 消