目錄
回复讨论(解决方案)
首頁 web前端 html教學 高手们,我这代码运行时为什么出错_html/css_WEB-ITnose

高手们,我这代码运行时为什么出错_html/css_WEB-ITnose

Jun 24, 2016 am 11:33 AM

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>CSS等高布局</title><script type="text/javascript" src="http://jt.875.cn/js/jquery.js"></script> <style type="text/css">#wrap{ overflow:hidden; width:1200px; margin:0 auto;}.top{    width:1200px;    height:150px;    background:#000;    margin-bottom: 10px; } .left{ float:left; width:150px; height:600px ; background:#00FFFF; }#center{    float:left;    width:880px;    height:1800px ;    background:#FF0000;    margin-right: 10px;    margin-left: 10px; }.right{ float:right; width:150px; height:600px ; background:#00FF00; } .bot{    width:1200px;    height:150px;    margin-top: 10px;    background-color: #00F; } </style></head><body><div id="wrap"> <div class="top"> </div>  <div class="left" id="left" > </div> <div id="center">  <p>center</p><p>center2</p><p>center3</p><p>center4</p><p>center5</p><p>center6</p><p>center7</p> </div> <div class="right" id="right"> </div>  <div class="bot"> </div> </div><script>var min_scroll=30;///触发效果的滚动条top值,$(document).scroll(function(){          if($(this).scrollTop()>=min_scroll&&!$('#left').attr('style'))    {           var right={'top':$('#right').offset().top,'left':$('#right').offset().left};        var left={'top':$('#left').offset().top,'left':$('#left').offset().left};        var center={'left':$('#center').position().left}        $('#center').css({'position':'absolute','left':center.left});        $('#left').css({'z-index':10,'position':'fixed','top':left.top,'left':left.left});        $('#right').css({'z-index':10,'position':'fixed','top':right.top,'left':right.left});    }    if($(this).scrollTop()<min_scroll&&$('#left').attr('style'))    {        $('#left').removeAttr('style');        $('#right').removeAttr('style');        $('#center').removeAttr('style');    }      });</script> </body></html>
登入後複製


效果就是这样,但是加入头部,和底部后,就变形了,两边的滚动那个上面永远有顶部高度的距离,想把这个距离去掉,另外底部自动跳到顶部的下面的。


回复讨论(解决方案)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>CSS等高布局</title><script type="text/javascript" src="http://jt.875.cn/js/jquery.js"></script> <style type="text/css">#wrap{ overflow:hidden; width:1200px; margin:0 auto;}.top{    width:1200px;    height:150px;    background:#000;    margin-bottom: 10px; }  .left{ float:left; width:150px; height:600px ; background:#00FFFF; }#center{    float:left;    width:880px;    height:1800px ;    background:#FF0000;    margin-right: 10px;    margin-left: 10px; }.right{ float:right; width:150px; height:600px ; background:#00FF00; } .bot{      float:left;    width:1200px;    height:150px;    margin-top: 10px;    background-color: #00F; }  </style></head><body><div id="wrap"> <div class="top"> </div>   <div class="left" id="left" > </div> <div id="center">  <p>center</p><p>center2</p><p>center3</p><p>center4</p><p>center5</p><p>center6</p><p>center7</p><p>center8</p><p>center9</p><p>center10</p> </div> <div class="right" id="right"> </div>  <div class="bot" id="bot"> </div>  </div><script>var min_scroll=30;///触发效果的滚动条top值,$(document).scroll(function(){           if($(this).scrollTop()>=min_scroll&&!$('#left').attr('style'))    {           var right={'top':0,'left':$('#right').offset().left};        var left={'top':0,'left':$('#left').offset().left};        var center={'left':$('#center').position().left}        var bot={'top':0,'left':$('#bot').offset().left}        $('#bot').css({'position':'fixed','left':bot.left,'top':bot.top,'margin':0});        $('#center').css({'position':'absolute','left':center.left});        $('#left').css({'z-index':10,'position':'fixed','top':left.top,'left':left.left});        $('#right').css({'z-index':10,'position':'fixed','top':right.top,'left':right.left});    }    if($(this).scrollTop()<min_scroll&&$('#left').attr('style'))    {        $('#left').removeAttr('style');        $('#bot').removeAttr('style');        $('#right').removeAttr('style');        $('#center').removeAttr('style');    }       });</script>  </body></html>
登入後複製
登入後複製

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>CSS等高布局</title><script type="text/javascript" src="http://jt.875.cn/js/jquery.js"></script> <style type="text/css">#wrap{ overflow:hidden; width:1200px; margin:0 auto;}.top{    width:1200px;    height:150px;    background:#000;    margin-bottom: 10px; }  .left{ float:left; width:150px; height:600px ; background:#00FFFF; }#center{    float:left;    width:880px;    height:1800px ;    background:#FF0000;    margin-right: 10px;    margin-left: 10px; }.right{ float:right; width:150px; height:600px ; background:#00FF00; } .bot{      float:left;    width:1200px;    height:150px;    margin-top: 10px;    background-color: #00F; }  </style></head><body><div id="wrap"> <div class="top"> </div>   <div class="left" id="left" > </div> <div id="center">  <p>center</p><p>center2</p><p>center3</p><p>center4</p><p>center5</p><p>center6</p><p>center7</p><p>center8</p><p>center9</p><p>center10</p> </div> <div class="right" id="right"> </div>  <div class="bot" id="bot"> </div>  </div><script>var min_scroll=30;///触发效果的滚动条top值,$(document).scroll(function(){           if($(this).scrollTop()>=min_scroll&&!$('#left').attr('style'))    {           var right={'top':0,'left':$('#right').offset().left};        var left={'top':0,'left':$('#left').offset().left};        var center={'left':$('#center').position().left}        var bot={'top':0,'left':$('#bot').offset().left}        $('#bot').css({'position':'fixed','left':bot.left,'top':bot.top,'margin':0});        $('#center').css({'position':'absolute','left':center.left});        $('#left').css({'z-index':10,'position':'fixed','top':left.top,'left':left.left});        $('#right').css({'z-index':10,'position':'fixed','top':right.top,'left':right.left});    }    if($(this).scrollTop()<min_scroll&&$('#left').attr('style'))    {        $('#left').removeAttr('style');        $('#bot').removeAttr('style');        $('#right').removeAttr('style');        $('#center').removeAttr('style');    }       });</script>  </body></html>
登入後複製
登入後複製




底部的BOT还是会把CENTER档上

你想哪个叠哪个 z-index就是表示他们重叠是时候显示的顺序,越大越在上面

你最好先理解下position的absolute,fixed还有与position搭配的top,bottom,left,right,z-index

你想哪个叠哪个 z-index就是表示他们重叠是时候显示的顺序,越大越在上面




我想想让bot不重叠,显示在最下面   谢谢了
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

公眾號網頁更新緩存難題:如何避免版本更新後舊緩存影響用戶體驗? 公眾號網頁更新緩存難題:如何避免版本更新後舊緩存影響用戶體驗? Mar 04, 2025 pm 12:32 PM

公眾號網頁更新緩存難題:如何避免版本更新後舊緩存影響用戶體驗?

如何使用HTML5表單驗證屬性來驗證用戶輸入? 如何使用HTML5表單驗證屬性來驗證用戶輸入? Mar 17, 2025 pm 12:27 PM

如何使用HTML5表單驗證屬性來驗證用戶輸入?

如何高效地在網頁中為PNG圖片添加描邊效果? 如何高效地在網頁中為PNG圖片添加描邊效果? Mar 04, 2025 pm 02:39 PM

如何高效地在網頁中為PNG圖片添加描邊效果?

HTML5中跨瀏覽器兼容性的最佳實踐是什麼? HTML5中跨瀏覽器兼容性的最佳實踐是什麼? Mar 17, 2025 pm 12:20 PM

HTML5中跨瀏覽器兼容性的最佳實踐是什麼?

&lt; datalist&gt;的目的是什麼。 元素? &lt; datalist&gt;的目的是什麼。 元素? Mar 21, 2025 pm 12:33 PM

&lt; datalist&gt;的目的是什麼。 元素?

我如何使用html5&lt; time&gt; 元素以語義表示日期和時間? 我如何使用html5&lt; time&gt; 元素以語義表示日期和時間? Mar 12, 2025 pm 04:05 PM

我如何使用html5&lt; time&gt; 元素以語義表示日期和時間?

&gt; gt;的目的是什麼 元素? &gt; gt;的目的是什麼 元素? Mar 21, 2025 pm 12:34 PM

&gt; gt;的目的是什麼 元素?

&lt; meter&gt;的目的是什麼。 元素? &lt; meter&gt;的目的是什麼。 元素? Mar 21, 2025 pm 12:35 PM

&lt; meter&gt;的目的是什麼。 元素?

See all articles