页面滚动时出现固定导航的效果,参考页面有http://v.thea.cn/course/info_358和v.thea.cn.
参考代码如下:
<div class="tab-title" style="position: static; top: 0px;"><span class="normal selected">课程介绍</span><span class="normal">课程大纲</span><span class="normal">课程评论</span>
<span style="display: none;" class="spa-try-listen "><a target="_blank" href="/play/358_3018">免费试听</a></span>
<span "="" style="display: none;" class="normal"><a href="/Cart/addCart/courseid/358/coursetype/0/wx/thea">购买课程</a></span><!-- /pay/course_358 --> </div>
js如下:
$(window).scroll(function(){ var scroll_offset = $(".pcd_main .tab").offset().top; var t = document.documentElement.scrollTop || document.body.scrollTop; //var $tabtitle=$(".pcd_main .tab-title"); //var $liLast=$tabtitle.children("span").last(); if(t>scroll_offset){ $tabtitle.css({"position":"fixed","top":"0"}); //$liLast.removeClass("last"); //$tabtitle.find(".spa-try-listen").show().next().show(); }else{ $tabtitle.css("position","static"); //$liLast.removeClass("last"); //$tabtitle.find(".spa-try-listen").hide().next().hide(); } });
时间: 2024-11-07 15:11:37