ÎÒ·¢ÏÖÏÖÔںܶàÍøÕ¾¶¼Ê¹ÓÃÁËÕâÖÖЧ¹û£¬±ÈÈç˵´¸×Ó¹ÙÍø¡¢elementui¹ÙÍø¡¢Ãëζ¿ÎÌõȣ¬²»µ¥µ¥ÓÐÊó±ê¸úËæµÄЧ¹û£¬Ëæ×ÅÊó±êµÄÒƶ¯»¹ÓÐÊÓ¾õ²îµÄЧ¹û£¬¿´ÆðÀ´ºÜ¸ß´óÉϵļ¼Êõ£¬ÆäʵʵÏÖÆðÀ´ºÜ¼òµ¥£¬Ö÷ÒªÀûÓÃcss3µÄtransform-styleºÍpersperctiveÊôÐÔ¡£
·Ï»°²»¶à˵ֱ½ÓÉÏ´úÂ룺
html£º
<div> <div> <span></span> <span>ÒÔ°ÁÂýÓëÆ«Ö´<br/>»Ø¾´°ÁÂýÓëÆ«¼û</span> </div> </div>
css£º
¹Ø¼üÉèÖãº
1¡¢ÎªÍâ²ãÈÝÆ÷ÉèÖÃperspectiveÊôÐÔ£¬Õâ¸öÊôÐÔÖµ¿ÉÒÔ×Ô¶¨Òå¿ÉÒÔÊÇÊýÖµ¡¢top/bottomµÈ
2¡¢°ÑÄãÏëÒªÉèÖÃΪÊÓ¾õ²îµÄÔªËØÉèÖÃΪ¾ø¶Ô¶¨Î»£¬²¢ÇÒÌí¼Ótransform£ºtanslateZ£¨deg£©ÊôÐÔ
* { font-family: "Microsoft YaHei"; transition: all .3s; -webkit-transition: all .3s; transition-timing-function: linear; -webkit-transition-timing-function: linear; } .perspective { perspective: 800px; } .preserve3d { position: relative; width: 600px; height: 300px; margin: 100px auto; background: url("http://static.smartisanos.cn/index/img/store/home/banner-3d-item-1-box-1_61bdc2f4f9.png") center no-repeat; background-size: 100% 100%; border-radius: 10px; transform-style: preserve-3d; } .preserve3d_img { position: absolute; width: 100%; height: 100%; bottom: 11px; left: 0; background: url("http://static.smartisanos.cn/index/img/store/home/banner-3d-item-1-box-3_8fa7866d59.png") center no-repeat; background-size: 95% 100%; -webkit-transform: translateZ(60px); } .preserve3d_text { position: absolute; top: 20%; right: 10%; font-size: 30px; color: #fff; text-align: right; font-weight: lighter; -webkit-transform: translateZ(40px); }
js£º
$('.preserve3d').on('mouseenter', function() { var thisPX = $(this).offset().left; var thisPY = $(this).offset().top; var boxWidth = $(this).outerWidth(); var boxHeight = $(this).outerHeight(); $(this).addClass("smart_3d"); }) .on('mousemove', function(event) { var mouseX = event.pageX - thisPX; var mouseY = event.pageY - thisPY; var X = mouseX - boxWidth/2; var Y = boxHeight/2 - mouseY; $(this).css({ "-webkit-transform": "rotateY(" + X / 50 + "deg) " + "rotateX(" + Y / 50 + "deg)" }); }) .on('mouseleave', function() { $(this).removeClass("smart3d"); $(this).css({ "-webkit-transform": "rotateY(0deg) rotateX(0deg)" }) })
ok,¾ÍÊÇÕâô¼òµ¥~»¹¿ÉÒÔÖ±½Ó×ö³ÉjQuery²å¼þ£¬¾ßÌå²Î¿¼£º https://github.com/tian0o0/html5/tree/master/smart_banner
¡¡