效果图如下:
在线预览 源码下载
html代码:
<p id="paper-back"> <nav> <p class="close"></p> <a href="#">home</a> <a href="#">about us</a> <a href="#">our work</a> <a href="#">contact</a> </nav> </p> <p id="paper-window"> <p id="paper-front"> <p class="hamburger"><span></span></p> <p id="container"> <section> <p>点击左上角的按钮打开菜单</p> <p>适用浏览器:、firefox、chrome、safari、opera、傲游、搜狗、世界之窗. <br>不支持ie及以下浏览器。</p> <p> <script src="/scripts/bc/_gg.js" type="text/javascript"></script></p> </section> <section></section> </p> </p> </p>
js代码:
var papermenu = { $window: $('#paper-window'), $paperfront: $('#paper-front'), $hamburger: $('.hamburger'), offset: , pageheight: $('#paper-front').outerheight(), open: function () { this.$window.addclass('tilt'); this.$hamburger.off('click'); $('#container, .hamburger').on('click', this.close.bind(this)); this.hamburgerfix(true); // console.log('opening...'); }, close: function () { this.$window.removeclass('tilt'); $('#container, .hamburger').off('click'); this.$hamburger.on('click', this.open.bind(this)); this.hamburgerfix(false); // console.log('closing...'); }, updatetransformorigin: function () { scrolltop = this.$window.scrolltop(); equation = (scrolltop + this.offset) / this.pageheight * ; this.$paperfront.css('transform-origin', 'center ' + equation + '%'); }, hamburgerfix: function (opening) { if (opening) { $('.hamburger').css({ position: 'absolute', top: this.$window.scrolltop() + + 'px' }); } else { settimeout(function () { $('.hamburger').css({ position: 'fixed', top: 'px' }); }, ); } }, bindevents: function () { this.$hamburger.on('click', this.open.bind(this)); $('.close').on('click', this.close.bind(this)); this.$window.on('scroll', this.updatetransformorigin.bind(this)); }, init: function () { this.bindevents(); this.updatetransformorigin(); } }; papermenu.init();
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
jquery实现表单里文字按钮特效合集
jquery实现带复选框表格步骤详解
以上就是jquery实现侧边栏菜单的详细内容。
