很多站长们,看到很多网站都有的效果,就是滚动页面时,当页面滚动到某一个DIV时,DIV就固定在页面顶部!这种效果其实很简单的
我这是以我的网站导航为例,所以代码有点多,自己可以自行修改,效果的主要代码是js部分
效果可以查看:魅网工作室--仿站教程 http://cqmeiwang.com/plus/list.php?tid=2
代码附下:
$(function (){
var ie6 = document.all;
//$('填写ID或者类')
var dv = $('.logo_daohang'), st;
dv.attr('otop', dv.offset().top);
$(window).scroll(function () {
st = Math.max(document.body.scrollTop || document.documentElement.scrollTop);
if (st > parseInt(dv.attr('otop'))) {
if (ie6) {//relative
dv.css({ position: 'absolute', top: st });
}
else if (dv.css('position') != 'fixed') dv.css({ 'position': 'fixed', top: 0 });
我这是以我的网站导航为例,所以代码有点多,自己可以自行修改,效果的主要代码是js部分
效果可以查看:魅网工作室--仿站教程 http://cqmeiwang.com/plus/list.php?tid=2
代码附下:
$(function (){
var ie6 = document.all;
//$('填写ID或者类')
var dv = $('.logo_daohang'), st;
dv.attr('otop', dv.offset().top);
$(window).scroll(function () {
st = Math.max(document.body.scrollTop || document.documentElement.scrollTop);
if (st > parseInt(dv.attr('otop'))) {
if (ie6) {//relative
dv.css({ position: 'absolute', top: st });
}
else if (dv.css('position') != 'fixed') dv.css({ 'position': 'fixed', top: 0 });