最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Jquery htmlcss: Creating drop shadow on fixed pos header that appears and disappears when scrollling - Stack Overfl

programmeradmin0浏览0评论

new to jquery here but I'm trying to learn some different stuff that's been done on websites I frequent.

One such case that I can't figure out, is how to create a drop shadow for a fixed positioned header, so that when you scroll a drop shadow appears under the header and then disappears when you aren't scrolling anything. Here's the website I frequent that uses this technique www.thisisluckyme

It doesn't seem too plex but I can't find much to go off of when trying to make this. Any help or insight into how its down would be very appreciated!

new to jquery here but I'm trying to learn some different stuff that's been done on websites I frequent.

One such case that I can't figure out, is how to create a drop shadow for a fixed positioned header, so that when you scroll a drop shadow appears under the header and then disappears when you aren't scrolling anything. Here's the website I frequent that uses this technique www.thisisluckyme.

It doesn't seem too plex but I can't find much to go off of when trying to make this. Any help or insight into how its down would be very appreciated!

Share Improve this question asked Dec 8, 2011 at 20:11 trying_hal9000trying_hal9000 4,4038 gold badges45 silver badges63 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

Pretty simple. You just bind an event handler to the window's scroll event, and check the position of the fixed header's top. If it's not 0, add the shadow. If it is 0, remove the 0.

Working example: http://jsfiddle/3cRe5/

the JS:

var header = $('.header');

$(window).scroll(function(e){
    if(header.offset().top !== 0){
        if(!header.hasClass('shadow')){
            header.addClass('shadow');
        }
    }else{
        header.removeClass('shadow');
    }
});

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论