課程
/前端開(kāi)發(fā)
/jQuery
/全屏切換效果
老師有源碼可以下載嗎?
2015-04-20
源自:全屏切換效果 1-1
正在回答
//自己寫(xiě)的,根據(jù)老師的思路,修正了bug
html
<!DOCTYPE?html> <html> <head> <meta?charset="UTF-8"> <title>Document</title> <style?type="text/css"> *{ padding:?0; margin:?0; } html,?body{ height:?100%; overflow:?hidden; } #container,?.sections,?.section{ height:?100%; } #section0,#section1,#section2,#section3{ background-color:?#000; background-size:?cover; background-position:?50%?50%; text-align:?center; color:?white; } #section0{ background-image:?url(images/1.jpg); } #section1{ background-image:?url(images/2.jpg); } #section2{ background-image:?url(images/3.jpg); } #section3{ background-image:?url(images/4.jpg); } .pages{ position:fixed; right:?10px; top:?50%; list-style:?none; } .pages?li{ width:?8px; height:?8px; border-radius:?50%; background:?#fff; margin:?0?0?10px?5px; } .pages?li.active{ width:?14px; height:?14px; border:?2px?solid?#FFFE00; background:?none; margin-left:?0; } </style> </head> <body> <div?id="container"> <div> <div?id="section0"> <h3>this?is?the?page1</h3> </div> <div?id="section1"> <h3>this?is?the?page2</h3> </div> <div?id="section2"> <h3>this?is?the?page3</h3> </div> <div?id="section3"> <h3>this?is?the?page4</h3> </div> </div> </div> <script?type="text/javascript"?src="jquery-1.11.2.min.js"></script> <script?type="text/javascript"?src="jqchange.js"></script> <script?type="text/javascript"> $('#container').PageSwitch(); </script> </body> </html>
js
(function?($)?{ //通過(guò)判斷js屬性的方式獲取前綴 var?_prefix?=?(function?(temp)?{ var?aPrefix?=?['webkit','Moz','o','ms'], props?=?''; for?(var?i?in?aPrefix)?{ props?=?aPrefix[i]?+?'Transition'; if?(temp.style[?props]?!==?undefined)?{ return?'-'?+?aPrefix[i].toLowerCase()?+?'-'; } } return?false; })(document.createElement(PageSwitch));//實(shí)參 //內(nèi)部實(shí)際主函數(shù) var?PageSwitch?=?(function?()?{ //element?=?外層 function?PageSwitch?(element,?options)?{ this.settings?=?$.extend(true,?$.fn.PageSwitch.defaults,?options||{}); this.element?=?element; this.init(); } PageSwitch.prototype?=?{ init?:?function?()?{ //全局公共方法,實(shí)現(xiàn)內(nèi)容 var?me?=?this;//保存pageSwitch對(duì)象 me.selectors?=?me.settings.selectors; me.sections?=?me.element.find(me.selectors.sections);//整個(gè)頁(yè)面框架 me.section?=?me.sections.find(me.selectors.section);//每個(gè)頁(yè)面元素 me.direction?=?me.settings.direction?=="vertical"??true?:?false; me.pagesCount?=?me.pagesCount();//頁(yè)面元素計(jì)數(shù) me.index?=(me.settings.index?>=?0?&&?me.settings.index?<?me.pagesCount)??me.settings.index?:?0;//初始頁(yè)面位置 me.canScroll?=?true; if(!me.direction)?{ me._initLayout();//初始化布局 } if(me.settings.pagination)?{ me._initPaging();//創(chuàng)建分頁(yè)處理 } me._initEvent();//事件綁定 me._scrollPage();//初始化位置 }, //獲取滑動(dòng)頁(yè)面數(shù)量 pagesCount?:?function?()?{ return?this.section.length; }, //獲取華東頁(yè)面寬度、高度 switchLength?:?function?()?{ return?this.direction??this.element.height()?:?this.element.width(); }, //向前滑動(dòng)上一個(gè)頁(yè)面 prev?:?function?()?{ var?me?=?this; if?(me.index?>?0)?{ me.index?--; }?else?if?(me.settings.loop)?{ me.index?=?me.pagesCount?-?1; } me._scrollPage(); }, //向后滑動(dòng)下一個(gè)頁(yè)面 next?:?function?()?{ var?me?=?this; if?(me.index?<?me.pagesCount?-?1)?{ me.index?++; }?else?if?(me.settings.loop)?{ me.index?=?0; } me._scrollPage(); }, //橫屏頁(yè)面布局 _initLayout?:?function?()?{ var?me?=?this; var?width?=?me.pagesCount?*?100?+?'%', cellWidth?=?(100/me.pagesCount).toFixed(2)?+?'%'; me.sections.width(width); me.section.width(cellWidth).css('float','left'); }, //創(chuàng)建分頁(yè)處理 _initPaging?:?function?()?{ var?me?=?this, pageClass?=?me.selectors.page.substring(1); me.activeClass?=?me.selectors.active.substring(1); var?pageHtml?=?'<ul?class="'+pageClass+'">'; for?(var?i?=?0;?i?<?me.pagesCount;?i++)?{ pageHtml?+=?'<li></li>'; } pageHtml?+='</ul>'; me.element.append(pageHtml); var?pages?=?me.element.find(me.selectors.page); me.pageItem?=?pages.find('li'); me.pageItem.eq(me.index).addClass(me.activeClass); if?(me.direction)?{ pages.addClass('vertical'); }?else?{ pages.addClass('horizontal'); } }, //事件綁定 _initEvent?:?function?()?{ var?me?=?this; //點(diǎn)擊事件 me.element.on('click',?me.selectors.page?+?'?li',?function()?{ if?(me.sections.is(":animated"))?{ me.sections.stop(true,true); } me.index?=?$(this).index(); me._scrollPage(); }); //滾輪事件 me.element.on('mousewheel?DOMMouseScroll',?function?(e)?{ if?(!me.canScroll)?{ return; } var?delta?=?e.originalEvent.wheelDelta?||?-?e.originalEvent.detail; //向上 if(delta?>?0?&&?((me.index?&&?!me.settings.loop)?||?me.settings.loop))?{ me.prev(); //向下 }?else?if?(delta?<?0?&&?((me.index?!=?(me.pagesCount?-?1)?&&?!me.settings.loop)?||?me.settings.loop))?{ me.next(); } }); //j鍵盤(pán)事件 if?(me.settings.keyboard)?{ $(window).on('keydown',function?(e)?{ if?(!me.canScroll)?{ return; } var?keyCode?=?e.keyCode; if?((keyCode?==?37?||?keyCode?==?38)?&&?((me.index?&&?!me.settings.loop)?||?me.settings.loop))?{ me.prev(); }?else?if?((keyCode?==?39?||?keyCode?==?40)?&&?((me.index?!=?(me.pagesCount?-?1)?&&?!me.settings.loop)?||?me.settings.loop))?{ me.next(); } }); } //窗口變化事件 $(window).resize(function?()?{ var?currentLength?=?me.switchLength(), offset?=?me.settings.direction??me.section.eq(me.index).offset().top?:?me.section.eq(me.index).offset().left; if?(Math.abs(offset)?>?currentLength/2?&&?me.index?<?(me.pagesCount?-?1))?{ me.index?++; } if?(me.index)?{ me._scrollPage(); } }); //動(dòng)畫(huà)結(jié)束后回調(diào)事件 me.sections.on('transitionend?webkitTransitionEnd?oTransitionEnd?otransitionEnd',?function?()?{ me.canScroll?=?true; if?(me.settings.callback?&&?$.type(me.settings.callback)?==?'function')?{ me.settings.callback(); } }); }, _scrollPage?:?function?()?{ var?me?=?this; me.canScroll?=?false; if?(_prefix)?{ me.sections.css(_prefix?+?'transition','all?'?+?me.settings.duration/1000?+?'s?'?+?me.settings.easing); var?translate?=?me.direction??'translateY(-'?+?me.switchLength()?*?me.index?+?'px)'?:?'translateX(-'?+?me.switchLength()?*?me.index?+?'px)'; me.sections.css(_prefix?+?'transform',?translate); }?else?{ var?animateCss?=?me.direction??{top?:?-me.switchLength()?*?me.index}?:?{left?:?-me.switchLength()?*?me.index}; me.sections.css('position','relative'); me.sections.animate(animateCss,?me.settings.direction,?function?()?{ me.canScroll?=?true; if?(me.settings.callback?&&?$.type(me.settings.callback)?==?'function')?{ me.settings.callback(); } }); } if?(me.settings.pagination)?{ me.pageItem.eq(me.index).addClass(me.activeClass).siblings('li').removeClass(me.activeClass); } } }; return?PageSwitch;//注冊(cè)全局方法 })(); /*-----------------------------------------------------------------*/ //主函數(shù) $.fn.PageSwitch?=?function?(options)?{ return?this.each(function?()?{ var?me?=?$(this), instance?=?me.data("PageSwitch");//檢驗(yàn)是否存在對(duì)象實(shí)例,用data存放對(duì)象的實(shí)例 if?(!instance)?{ instance?=?new?PageSwitch(me,?options);//從內(nèi)部實(shí)際主函數(shù)(全局方法)中新建實(shí)例并存儲(chǔ) me.data("PageSwitch",?instance);//保存到data里面 } //判斷傳入?yún)?shù)如果是字符串,返回該字符串方法調(diào)用 if?($.type(options)?==="string")?{?return?instance[options]();} //在使用時(shí)訪問(wèn)元素的繼承方法init //$("div").PageSwitch("init"); }); }; //參數(shù) $.fn.PageSwitch.defaults?=?{ selectors?:?{ sections?:?".sections", section?:?".section", page?:?".pages", active?:?".active" }, index?:?0, easing?:?"ease", duration?:?500,//毫秒 loop?:?false, pagination?:?true,//分頁(yè) keyboard?:?true, direction?:?"vertical", callback?:?"" }; /*-----------------------------------------------------------------*/ //可通過(guò)屬性的方式全局執(zhí)行一次初始化 $(function?()?{ $("[data-PageSwitch]").PageSwitch(); }); })(jQuery);
舉報(bào)
如何在PC和移動(dòng)端實(shí)現(xiàn)全屏切換效果,本課程會(huì)給你答案
1 回答可以下載源碼嗎?
1 回答可以提高一下源代碼嗎?
1 回答源碼下載~
1 回答有源碼嗎?
1 回答有沒(méi)有代碼,可以參考下
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢(xún)優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2015-12-16
html
js