大神,我这代码运行时为什么出错?_html/css_WEB-ITnose

php中文网
发布: 2016-06-21 09:04:20
原创
1450人浏览过

<!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;}.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; }</style></head><body><div id="wrap"> <div class="left" id="left"> <script type="text/javascript"> $.fn.smartfloat = function() { var position = function(element) { var top = element.position().top, pos = element.css("position"); $(window).scroll(function() { var scrolls = $(this).scrolltop(); if (scrolls > top) { if (window.xmlhttprequest) { element.css({ position: "fixed", top: 0 }); } else { element.css({ top: scrolls }); } }else { element.css({ position: pos, top: top }); } }); }; return $(this).each(function() { position($(this)); }); }; //绑定 $("#left").smartfloat(); </script>  </div> <div id="center">  <p>center</p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免费学习笔记(深入)</a>”;</p> </div> <div class="right" id="right">   <script type="text/javascript"> $.fn.smartFloat = function() { var position = function(element) { var top = element.position().top, pos = element.css("position"); $(window).scroll(function() { var scrolls = $(this).scrollTop(); if (scrolls > top) { if (window.XMLHttpRequest) { element.css({ position: "fixed", top: 0 }); } else { element.css({ top: scrolls }); } }else { element.css({ position: pos, top: top }); } }); }; return $(this).each(function() { position($(this)); }); }; //绑定 $("#right").smartFloat(); </script>  </div></div></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;}.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; }</style></head><body><div id="wrap"> <div class="left" id="left" > </div> <div id="center">  <p>center</p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免费学习笔记(深入)</a>”;</p><p>center2</p><p>center3</p><p>center4</p><p>center5</p><p>center6</p><p>center7</p>
                    <div class="aritcle_card">
                        <a class="aritcle_card_img" href="/ai/1365">
                            <img src="https://img.php.cn/upload/ai_manual/000/000/000/175679975740787.png" alt="腾讯云AI代码助手">
                        </a>
                        <div class="aritcle_card_info">
                            <a href="/ai/1365">腾讯云AI代码助手</a>
                            <p>基于混元代码大模型的AI辅助编码工具</p>
                            <div class="">
                                <img src="/static/images/card_xiazai.png" alt="腾讯云AI代码助手">
                                <span>98</span>
                            </div>
                        </div>
                        <a href="/ai/1365" class="aritcle_card_btn">
                            <span>查看详情</span>
                            <img src="/static/images/cardxiayige-3.png" alt="腾讯云AI代码助手">
                        </a>
                    </div>
                 </div> <div class="right" id="right"><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> </div></div></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><span>立即学习</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免费学习笔记(深入)</a>”;</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>
登录后复制

HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号