這篇文章主要介紹了使用JavaScript怎么編寫一個(gè)旋轉(zhuǎn)木馬效果,創(chuàng)新互聯(lián)建站小編覺得不錯(cuò),現(xiàn)在分享給大家,也給大家做個(gè)參考,一起跟隨創(chuàng)新互聯(lián)建站小編來看看吧!
創(chuàng)新互聯(lián)公司一直在為企業(yè)提供服務(wù),多年的磨煉,使我們?cè)趧?chuàng)意設(shè)計(jì),成都營(yíng)銷網(wǎng)站建設(shè)到技術(shù)研發(fā)擁有了開發(fā)經(jīng)驗(yàn)。我們擅長(zhǎng)傾聽企業(yè)需求,挖掘用戶對(duì)產(chǎn)品需求服務(wù)價(jià)值,為企業(yè)制作有用的創(chuàng)意設(shè)計(jì)體驗(yàn)。核心團(tuán)隊(duì)擁有超過10余年以上行業(yè)經(jīng)驗(yàn),涵蓋創(chuàng)意,策化,開發(fā)等專業(yè)領(lǐng)域,公司涉及領(lǐng)域有基礎(chǔ)互聯(lián)網(wǎng)服務(wù)四川雅安電信機(jī)房、重慶APP開發(fā)、手機(jī)移動(dòng)建站、網(wǎng)頁設(shè)計(jì)、網(wǎng)絡(luò)整合營(yíng)銷。代碼如下:
<html class=" js csstransforms3d" lang="zh"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS3 3D transforms-旋轉(zhuǎn)木馬</title> <link rel="stylesheet" type="text/css" href="http://www.htmleaf.com/pins/1412/201502062108/css/style.css" rel="external nofollow" > <style media="screen"> .container { width: 210px; height: 140px; position: relative; margin: 50px auto 40px; border: 1px solid #CCC; -webkit-perspective: 1100px; -moz-perspective: 1100px; -o-perspective: 1100px; perspective: 1100px; } #carousel { width: 100%; height: 100%; position: absolute; -webkit-transform-style: preserve-3d; -moz-transform-style: preserve-3d; -o-transform-style: preserve-3d; transform-style: preserve-3d; } .ready #carousel { -webkit-transition: -webkit-transform 1s; -moz-transition: -moz-transform 1s; -o-transition: -o-transform 1s; transition: transform 1s; } #carousel.panels-backface-invisible figure { -webkit-backface-visibility: hidden; -moz-backface-visibility: hidden; -o-backface-visibility: hidden; backface-visibility: hidden; } #carousel figure { display: block; position: absolute; width: 186px; height: 116px; left: 10px; top: 10px; border: 2px solid black; line-height: 116px; font-size: 80px; font-weight: bold; color: white; text-align: center; } .ready #carousel figure { -webkit-transition: opacity 1s, -webkit-transform 1s; -moz-transition: opacity 1s, -moz-transform 1s; -o-transition: opacity 1s, -o-transform 1s; transition: opacity 1s, transform 1s; } #options{ margin-top: 200px; width: 100%; text-align: center; } #options button{padding: 0.5em 1.5em;border: 2px solid #6699cc;background: #fff;} </style> <!--[if IE]> <script src="http://libs.useso.com/js/html5shiv/3.7/html5shiv.min.js"></script> <![endif]--> </head> <section class="container"> <div id="carousel" > <figure >1</figure> <figure >2</figure> <figure >3</figure> <figure >4</figure> <figure >5</figure> <figure >6</figure> <figure >7</figure> <figure >8</figure> <figure >9</figure> <figure >10</figure> <figure >11</figure> <figure >12</figure> <figure >13</figure> <figure >14</figure> <figure >15</figure> <figure >16</figure> <figure >17</figure> <figure >18</figure> <figure >19</figure> <figure >20</figure> </div> </section> <section id="options"> <p> <label for="panel-count">個(gè)數(shù)</label> <input id="panel-count" value="9" min="3" max="20" type="range"> <span class=" range-display"></span></p> <p id="navigation"> <button id="previous" data-increment="-1">上一頁</button> <button id="next" data-increment="1">下一頁</button> </p> <p> <button id="toggle-axis">橫豎切換</button> </p> <p> <button id="toggle-backface-visibility">背面可見切換</button> </p> </section> </div> <script src="http://www.htmleaf.com/pins/1412/201502062108/js/utils.js"></script> <script> var transformProp = Modernizr.prefixed('transform'); function Carousel3D ( el ) { this.element = el; this.rotation = 0; this.panelCount = 0; this.totalPanelCount = this.element.children.length; this.theta = 0; this.isHorizontal = true; } Carousel3D.prototype.modify = function() { var panel, angle, i; this.panelSize = this.element[ this.isHorizontal ? 'offsetWidth' : 'offsetHeight' ]; this.rotateFn = this.isHorizontal ? 'rotateY' : 'rotateX'; this.theta = 360 / this.panelCount; // do some trig to figure out how big the carousel // is in 3D space this.radius = Math.round( ( this.panelSize / 2) / Math.tan( Math.PI / this.panelCount ) ); for ( i = 0; i < this.panelCount; i++ ) { panel = this.element.children[i]; angle = this.theta * i; panel.style.opacity = 1; panel.style.backgroundColor = 'hsla(' + angle + ', 100%, 50%, 0.8)'; // rotate panel, then push it out in 3D space panel.style[ transformProp ] = this.rotateFn + '(' + angle + 'deg) translateZ(' + this.radius + 'px)'; } // hide other panels for ( ; i < this.totalPanelCount; i++ ) { panel = this.element.children[i]; panel.style.opacity = 0; panel.style[ transformProp ] = 'none'; } // adjust rotation so panels are always flat this.rotation = Math.round( this.rotation / this.theta ) * this.theta; this.transform(); }; Carousel3D.prototype.transform = function() { // push the carousel back in 3D space, // and rotate it this.element.style[ transformProp ] = 'translateZ(-' + this.radius + 'px) ' + this.rotateFn + '(' + this.rotation + 'deg)'; }; var init = function() { var carousel = new Carousel3D( document.getElementById('carousel') ), panelCountInput = document.getElementById('panel-count'), axisButton = document.getElementById('toggle-axis'), navButtons = document.querySelectorAll('#navigation button'), onNavButtonClick = function( event ){ var increment = parseInt( event.target.getAttribute('data-increment') ); carousel.rotation += carousel.theta * increment * -1; carousel.transform(); }; // populate on startup carousel.panelCount = parseInt( panelCountInput.value, 10); carousel.modify(); axisButton.addEventListener( 'click', function(){ carousel.isHorizontal = !carousel.isHorizontal; carousel.modify(); }, false); panelCountInput.addEventListener( 'change', function( event ) { carousel.panelCount = event.target.value; carousel.modify(); }, false); for (var i=0; i < 2; i++) { navButtons[i].addEventListener( 'click', onNavButtonClick, false); } document.getElementById('toggle-backface-visibility').addEventListener( 'click', function(){ carousel.element.toggleClassName('panels-backface-invisible'); }, false); setTimeout( function(){ document.body.addClassName('ready'); }, 0); }; window.addEventListener( 'DOMContentLoaded', init, false); </script> <p id="disclaimer">對(duì)不起,你的瀏覽器不支持CSS 3D transforms。</p> </body></html>
以上就是創(chuàng)新互聯(lián)建站小編為大家收集整理的使用JavaScript怎么編寫一個(gè)旋轉(zhuǎn)木馬效果,如何覺得創(chuàng)新互聯(lián)建站網(wǎng)站的內(nèi)容還不錯(cuò),歡迎將創(chuàng)新互聯(lián)建站網(wǎng)站推薦給身邊好友。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站aaarwkj.com,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)站題目:使用JavaScript怎么編寫一個(gè)旋轉(zhuǎn)木馬效果-創(chuàng)新互聯(lián)
標(biāo)題路徑:http://aaarwkj.com/article28/dpgecp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、靜態(tài)網(wǎng)站、網(wǎng)站導(dǎo)航、手機(jī)網(wǎng)站建設(shè)、企業(yè)網(wǎng)站制作、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容