前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【答疑释惑】固定菜单滚动

【答疑释惑】固定菜单滚动

作者头像
程序员互动联盟
发布2018-03-13 17:01:28
9840
发布2018-03-13 17:01:28
举报

分享一下滚动菜单源码,可以直接用,希望对盟友有帮助

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8"/>

<title>test</title>

<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.8.3/jquery.min.js"></script>

<style type="text/css">

*{ margin:0; padding:0;}

.ndiv{ width:200px; height:400px; border:1px solid #ccc;background: #f1f1f1;}

.fix-div{ position:fixed; top:0px;}

</style>

</head>

<body>

<section style="height: 700px;"></section>

<div id="mydiv" class="ndiv" >di222v</div>

<section style="height: 700px;"></section>

<script type="text/javascript">

$.fn.fixedDiv = function(actCls){

var pos = 0,

that = $(this),

topVal;

if(that.length > 0){

topVal = that.offset().top;

}

function fix(){

pos = $(document).scrollTop();

if (pos > topVal) {

that.addClass(actCls);

if (!window.XMLHttpRequest) {

that.css({

position: 'absolute',

top : pos

});

}

} else {

that.removeClass(actCls);

if (!window.XMLHttpRequest) {

that.css({

position: 'static',

top : 'auto'

});

}

}

}

fix();

$(window).scroll(fix);

}

$('#mydiv').fixedDiv('fix-div');

</script>

</body>

</html>

转自http://www.cnblogs.com/jikey/p/3773732.html

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2015-07-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 程序员互动联盟 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档