垂直滚动不起作用

发布于 2024-12-12 01:40:26 字数 2000 浏览 0 评论 0原文

对于以下代码,垂直滚动条似乎根本没有向下滚动来查看文本?非常感谢任何帮助。尝试过更改溢出和定位,但没有成功。也许是javascipt的问题?或者是css和js之间有冲突?谢谢:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"       type="text/javascript"></script>
 <title>AUTO RESIZE BACKGROUND IMAGE</title>
 <script type="text/javascript">
 $(document).ready(function() {
      $("#triquibackimg").load(function(){
           resize_bg();
      })
      $(window).resize(function(){
           resize_bg();
      })
      function resize_bg(){
           $("#triquibackimg").css("left","0");
           var doc_width = $(window).width();
           var doc_height = $(window).height();
           var image_width = $("#triquibackimg").width();
           var image_height = $("#triquibackimg").height();
           var image_ratio = image_width/image_height;      
           var new_width = doc_width;
           var new_height = Math.round(new_width/image_ratio);
           if(new_height<doc_height){
                new_height = doc_height;
                new_width = Math.round(new_height*image_ratio);
                var width_offset = Math.round((new_width-doc_width)/2);
                $("#triquibackimg").css("left","-"+width_offset+"px");
           }
           $("#triquibackimg").width(new_width);
           $("#triquibackimg").height(new_height);
      }
 });      
 </script>
 <style type="text/css">
      #triquiback{
           left: 0;
           top: 0;
           position:fixed;
           overflow: auto;
           zIndex: -9999
      }
      #triquibackimg{
           position:relative    
      }      
 </style>
</head>
<body>
 <div id = "triquiback">
      <img id = "triquibackimg" src =     "http://www.lightmedia.hu/hirlevel/sonybmg/foofighters/061124/sajto_2.jpg" />
 </div>

<div>

hi
</div>
</body>
</html>

For the following code the vertical scrollbar does not seem to scroll down at all to view the text? Any help greatly appreciated. Have tried changing both overflow and positioning but did not work. Maybe an issue with the javascipt possibly? Or maybe a conflict between the css and js? Thanks:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"       type="text/javascript"></script>
 <title>AUTO RESIZE BACKGROUND IMAGE</title>
 <script type="text/javascript">
 $(document).ready(function() {
      $("#triquibackimg").load(function(){
           resize_bg();
      })
      $(window).resize(function(){
           resize_bg();
      })
      function resize_bg(){
           $("#triquibackimg").css("left","0");
           var doc_width = $(window).width();
           var doc_height = $(window).height();
           var image_width = $("#triquibackimg").width();
           var image_height = $("#triquibackimg").height();
           var image_ratio = image_width/image_height;      
           var new_width = doc_width;
           var new_height = Math.round(new_width/image_ratio);
           if(new_height<doc_height){
                new_height = doc_height;
                new_width = Math.round(new_height*image_ratio);
                var width_offset = Math.round((new_width-doc_width)/2);
                $("#triquibackimg").css("left","-"+width_offset+"px");
           }
           $("#triquibackimg").width(new_width);
           $("#triquibackimg").height(new_height);
      }
 });      
 </script>
 <style type="text/css">
      #triquiback{
           left: 0;
           top: 0;
           position:fixed;
           overflow: auto;
           zIndex: -9999
      }
      #triquibackimg{
           position:relative    
      }      
 </style>
</head>
<body>
 <div id = "triquiback">
      <img id = "triquibackimg" src =     "http://www.lightmedia.hu/hirlevel/sonybmg/foofighters/061124/sajto_2.jpg" />
 </div>

<div>

hi
</div>
</body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

擦肩而过的背影 2024-12-19 01:40:26

您需要将文本包装在具有某种定位的容器中(相对应该适合所有目的),否则它将保留在其他定位元素的后面。这是一个示例: http://jsfiddle.net/VkQ67/1/

You need to wrap your text in a container which has some kind of positioning (relative should be fine for all purposes), otherwise it'll stay behind the other positioned element. Here's an example: http://jsfiddle.net/VkQ67/1/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文