2012-06-09 119 views
0

我在我的网站中插入了一个小小的jQuery代码,来修复左右导航图标。问题是,它只适用于调整bowser窗口的大小,但它应该把文件加载后的图标正确...在这里你可以看到这在行动(匈牙利语言):utravalo.comjquery在页面加载时不起作用

此代码工程在我的其他网站上,没有问题。我是一个有点困惑... :)

这是jQuery代码:

if (jQuery) { 
    /* obtain jQuery instance */ 
    $sdv = jQuery.noConflict(); 

    /* ensure the links look & feel consistent */ 
    var formatLink = function (strEl) { 
      var pEl = $sdv(strEl); 
      if (pEl.length > 0) { 
       pEl.children().children().css('color', '#3D536C'); 
       pEl.children().children().hover(

       function() { 
        $sdv(this).css('color', '#444444'); 
       }, function() { 
        $sdv(this).css('color', '#3D536C'); 
       }); 
      } 
     } 
    formatLink("#divPrev"); 
    formatLink("#divNext"); 

    var fnModifyNavigation = function() { 
      /* obtain window's width */ 
      var w = $sdv(window).width(); 
      var hw = (w - 1020)/2; 
      if (hw > 100) { 
       /* we have enough space for the fixed postion links */ 
       jQFPL($sdv("#divPrev"), 'left', 0, hw); 
       jQFPL($sdv("#divNext"), 'right', 0, hw); 
       $sdv("#divPostNav").hide(); 
      } else { 
       /* not enough space for the fixed postion links */ 
       var divNav = $sdv("#divPostNav"); 
       if (divNav.length > 0) { 
        if (divNav.css('display') == 'none') { 
         divNav.show(); 
         divNav.prepend(jQSPL("#divNext", "right")); 
         divNav.prepend(jQSPL("#divPrev", "left")); 
        } 
       } 
      } 
     } 

     /* jQuery Fixed Position Link */ 
    var jQFPL = function (el, remClass, absPosPX, width) { 
      var pEl = el.detach(); 
      if (pEl) { 
       pEl.removeClass(remClass); 
       eval("var objStyle = { 'position':'fixed', 'top':'250px', 'width': '" + width + "px', '" + remClass + "':'" + absPosPX + "px', 'text-align':'" + remClass + "'};"); 
       pEl.css(objStyle); 
       pEl.appendTo("body"); 
      } 
     } 

     /* jQuery Static Position Link*/ 
    var jQSPL = function (strEl, strFloat) { 
      var el = $sdv(strEl).detach(); 
      el.css('position', 'static'); 
      el.css('width', '50%'); 
      el.css('float', strFloat); 
      return el; 
     } 

     /* run position modification routine after the document is loaded */ 
     $sdv(fnModifyNavigation); 

    /* handle the window's resize event and run position modification routine again */ 
    $sdv(window).resize(fnModifyNavigation); 
} 

感谢您的帮助!

回答

1

您要运行的修改资产净值,并在jQuery的准备方法formatLink功能(此等待的HTML加载):

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

     formatLink("#divPrev"); 
     formatLink("#divNext"); 

     /* run position modification routine 
     after the document is loaded */ 
     $sdv(fnModifyNavigation); 

     /* handle the window's resize event 
     and run position modification routine again */ 
     $sdv(window).resize(fnModifyNavigation); 
    } 
); 
+0

非常感谢你!与此它的作品:)但我不知道它如何能在另一方面没有这个工作...:S – VORiAND

+0

我很高兴它的作品:)虽然我不知道你的意思是'对方“? –

+0

对不起,错字:)我的意思是:“其他网站”:) – VORiAND

0

修改的最后一行,

$sdv(window).resize(fnModifyNavigation); 

$sdv(window).resize(fnModifyNavigation).resize(); 
相关问题