在线查看时网站无法正常工作

时间:2012-02-08 04:34:35

标签: forms web size

我刚刚为客户instantinteriors.com.au建立了一个网站。 (访问此站点获取源代码。)

出于某种原因,当我将Firefox中的网站作为文件离线查看时,它看起来应该是这样的。上传后,大小调整会变得不同,例如字体和div大小。我的一些脚本也无法运行。

该网站似乎在Safari和Chrome中运行正常,尚未在Windows上进行过检查。表单似乎也有问题,因为我已准备好工作和测试,但是一旦它进入主机服务器,客户端使用它就会失败。

我强调客户端服务器的原因是,当我在主机上测试它时,我使用它工作正常。

以下是许多似乎失败的脚本之一...

 <script type="text/javascript">
     $.fn.hasOverflow = function() {
     var $this = $(this);
     var $children = $this.find('*');
     var len = $children.length;

     if (len) {
       var maxWidth = 0;
       var maxHeight = 0
       $children.map(function(){
        maxWidth = Math.max(maxWidth, $(this).outerWidth(true));
        maxHeight = Math.max(maxHeight, $(this).outerHeight(true));
     });

     return maxWidth > $this.width() || maxHeight > $this.height();
    }

    return false;
    };

  $(function() {
   var $content = $('#wrap4').children().wrapAll('<div>');
   if($content.hasOverflow()){
       $("#arrows").css("display", "none");
   } else {
     $("#arrows").css("display", "block");
   }
 });

 </script>

1 个答案:

答案 0 :(得分:0)

你的逻辑是否正确?当maxWidth或maxHeight大于当前宽度和高度时,hasOverflow函数返回true。如果你有溢出,如果当前值大于最大值,那么不应该进行测试吗?

您应该切换使用hasOverflow结果的方式,以便在出现溢出时显示箭头。您可以使用show()hide()方法作为简写。

if($content.hasOverflow()) {
  $("#arrows").show();
} else {
  $("#arrows").hide();
}

文档准备好后会调用它吗?源格式化很难说清楚。