html+css+jquery右侧固定功能

 时间:2024-10-17 04:39:24

1、新建html文档。

html+css+jquery右侧固定功能

2、书写hmtl代码。<div class="box"> <!--代码开始--> <div class="main"></div> <div class="sub"> <div class="sub01"></div> <div class="sub01"></div> <div class="fixed">我是固定的哟</div> </div> <!--代码结束--></div>

html+css+jquery右侧固定功能

3、书写css代码。<style>*{ padding:0px; margin:0px;}.box{ width:1000px; background:#ccc; margin:0 auto; overflow:hidden;}.main{ width:770px; height:2000px; background:#000; float:left;}.sub{ width:220px; background:#FC6; float:right;}.sub01{ width:220px; height:100px; background:#0CC; margin-bottom:10px;}.fixed{ width:220px; height:300px; background:#F66; font:normal 13px/30px \5FAE\8F6F\96C5\9ED1; text-align:center; top:10px;}</style>

html+css+jquery右侧固定功能

4、书写并引用js。<script src="js/jquery.js">媪青怍牙</script><script>$(document).ready(function(e) { t = $('.fixed').offset().top; mh = $('.main').height(); fh = $('.fixed').height(); $(window).scroll(function(e){ s = $(document).scrollTop(); if(s > t - 10){ $('.fixed').css('position','fixed'); if(s + fh > mh){ $('.fixed').css('top',mh-s-fh+'px'); } }else{ $('.fixed').css('position',''); } })});</script>

html+css+jquery右侧固定功能

5、代码整体结构。

html+css+jquery右侧固定功能

6、查看效果。第一张加载前,第二张为鼠标滚动之后。

html+css+jquery右侧固定功能
html+css+jquery右侧固定功能
  • html+css+jquery实现天气效果
  • html+css+jQuery左右弹性焦点图滚动
  • html+css+jQuery实现鼠标滑过鼠标变色功能
  • html+css+jQuery会员注册表单
  • html+css+jQuery顶部可关闭提示框代码
  • 热门搜索
    手抄报图片花边 圣诞节的手抄报 抗病毒手抄报图片 世界环境日手抄报 同讲普通话携手进小康手抄报内容 青少年心理健康手抄报 推广普通话手抄报句子 清明节的手抄报三年级 国防教育手抄报内容 中学生英语手抄报