jquery - CSS perspective and translateZ not working properly in FF and Safari -
i have created cover flow using css3 perspective , translatez, demo here
it has transition effect when clicking through. works perfect on chrome , ie10, mobile safari 7. however, has few problems on firefox , desktop safari.
- on firefox(latest 29.0.1), clicking on image not put 0 position (flat view). cannot click through layers below. when first image current image, cannot click on third 1 directly, unless click second , make current first.
- on desktop safari (5, on both pc , mac), transition works partly, not smooth acceptable. main problem no matter image clicks, triggers downloads immediately, while code supposed download when image current one.
structure simple: html
<div class="product-download"> <div id="product-image"> <img src="//placehold.it/360x259" /> <span class="download-title">product image</span> </div> <div id="in-situ-image"> <img src="//placehold.it/360x259" /> <span class="download-title">in-situ image</span> </div> <div id="product-flyer"> <img src="//placehold.it/360x259" /> <span class="download-title">product flyer</span> </div> <div id="data-sheet"> <img src="//placehold.it/360x259" /> <span class="download-title">data sheet</span> </div> </div>
css
body { width:100%; } .product-download { position:relative; width:900px !important; height:397px; margin: 0 auto; transform: perspective(0px) rotatey(0deg) translatez(0px); -ms-transform: perspective(0px) rotatey(0deg) translatez(0px); -moz-transform: perspective(0px) rotatey(0deg) translatez(0px); -webkit-transform: perspective(0px) rotatey(0deg) translatez(0px); cursor:pointer; margin-top:50px; margin-left:30px; } .product-download > div { width:360px; height:289px; position:absolute; display:inline-block; transition: 1s; } #product-image { z-index:9999; transform: perspective(0px) rotatey(0deg) translatez(0px); -ms-transform: perspective(0px) rotatey(0deg) translatez(0px); -moz-transform: perspective(0px) rotatey(0deg) translatez(0px); -webkit-transform: perspective(0px) rotatey(0deg) translatez(0px); } #in-situ-image { transform: perspective(600px) rotatey(-30deg) translatez(-100px); -ms-transform: perspective(600px) rotatey(-30deg) translatez(-100px); -moz-transform: perspective(600px) rotatey(-30deg) translatez(-100px); -webkit-transform: perspective(600px) rotatey(-30deg) translatez(-100px); z-index:5; left:150px; } #product-flyer { transform: perspective(600px) rotatey(-30deg) translatez(-100px); -ms-transform: perspective(600px) rotatey(-30deg) translatez(-100px); -moz-transform: perspective(600px) rotatey(-30deg) translatez(-100px); -webkit-transform: perspective(600px) rotatey(-30deg) translatez(-100px); z-index:4; left:330px; } #data-sheet { transform: perspective(600px) rotatey(-30deg) translatez(-100px); -ms-transform: perspective(600px) rotatey(-30deg) translatez(-100px); -moz-transform: perspective(600px) rotatey(-30deg) translatez(-100px); -webkit-transform: perspective(600px) rotatey(-30deg) translatez(-100px); z-index:3; left:510px; } .download-title { width:300px; height:30px; font: italic bold 18px/30px helvetica, serif; position:absolute; text-align:center; display:none; } #product-image >span { display:block; }
jquery
$('.product-download div').click(function () { $(this).fadeto('slow').css({ 'transform': 'perspective( 0px ) rotatey( 0deg ) translatez(0px)', '-ms-transform': 'perspective( 0px ) rotatey( 0deg ) translatez(0px)', '-webkit-transform': 'perspective( 0px ) rotatey( 0deg ) translatez(0px)' }).css('z-index', '9999'); $(this).prevall().fadeto('slow').css({ 'transform': 'perspective( 600px ) rotatey( 30deg ) translatez(-100px)', '-ms-transform': 'perspective( 600px ) rotatey( 30deg ) translatez(-100px)', '-webkit-transform': 'perspective( 600px ) rotatey( 30deg ) translatez(-100px)' }).css('z-index', '1'); $(this).nextall().each(function (index) { $(this).fadeto('slow').css({ 'transform': 'perspective( 600px ) rotatey( -30deg ) translatez(-100px)', '-ms-transform': 'perspective( 600px ) rotatey( -30deg ) translatez(-100px)', '-webkit-transform': 'perspective( 600px ) rotatey( -30deg ) translatez(-100px)' }).css('z-index', '-' + index); }); $('.download-title').css('display', 'none'); $(this).children('span').eq(0).css('display', 'block'); event.preventdefault(); if ($(this).css('z-index') == 9999) { event.preventdefault(); window.open('//placehold.it/200x200&text=download', '_blank'); } });
your applying z-index: 9999
immediately, why tests true , triggers download (although why varies browser isn't clear).
you could:
- move z-index declaration
fadeto
function - move
if
test before transitions (this easiest way) - test on other z-index, perhaps use class explicitly identify 'current' item, rather relying on browser implementations of z-indexing
Comments
Post a Comment