私のページには一連のdivがあります。各divは背景画像を持ち、格子状に配置されています。私のページにはdivの個数があります。ページは、使用するサイズに制限されています<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
センターとズームにcss3変換元を使用
divをクリックして特定の縮尺にスケールし、中央に配置したいと考えています。
私のマークアップ:
<body id="body">
<div id="container" style="position: relative">
<div id="pack1" class="screenItem cardPack"></div>
<div id="pack2" class="screenItem cardPack"></div>
<div id="pack3" class="screenItem cardPack"></div>
<div id="pack4" class="screenItem cardPack"></div>
</div>
</body>
私のCSS:
#pack1{
margin-left: 20px;
margin-top: 20px;
height: 193px;
width: 127px;
background-image: url(../images/image1.png);
background-size: 100% 100%;
float: left;
clear: both;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
}
#pack2{
margin-right: 20px;
margin-top: 20px;
height: 193px;
width: 127px;
background-image: url(../images/image2.png);
background-size: 100% 100%;
float: right;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
}
#pack3{
margin-left: 20px;
margin-top: 20px;
height: 193px;
width: 127px;
background-image: url(../images/image3.png);
background-size: 100% 100%;
float: left;
clear: both;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
}
#pack4{
margin-right: 20px;
margin-top: 20px;
height: 193px;
width: 127px;
background-image: url(../images/comingSoon.png);
background-size: 100% 100%;
float: right;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
}
#body,
.ui-page {
background-image: url(../images/bg.png);
background-size: auto 100%;
background-repeat: repeat-x;
}
#container {
margin: auto;
width: 310px;
height: 568px;
}
私はほとんど機能しファッジがあります。
$(cardPack).click(function() {
var left = $(cardPack).position().left;
var top = $(cardPack).position().top;
$(cardPack).css("-webkit-transform", "scale(2.5,2.5)");
$(cardPack).css("-webkit-transform-origin", (3*(left/4)) + " " + (3*(top/4)));
});
をしかし、私はそれが偶然と運のより多くのだと思います。私の脳は、私がどこで始動点に関係なく、画面の中央に画像が終わるように、どこでtransform-origin
を設定するかを練習できるところまでは働いていません。
これを実現するには、transform-origin
の代替手段を検討してください。
EDIT: 「それはローカルでないと全く同じに動作していない」jsfiddle:ここではhttp://jsfiddle.net/a7Cks/9/
'.offset'ではなく、' .offset'をドキュメントに対して相対的なオフセットとして使いたいと思いますが、 '.position'は親に対して相対的です。 –
Nope - オフセットはそれをさらに悪化させます - 位置は中心にかなり近い値を与えます(少なくとも1回は悪い数学でそれを悪用します) –
http://jsfiddle.netでコードを実演し、絶対パスを使用できますか?画像(またはダミー画像)が表示されるようにしますか?そうすれば、人々が編集/遊びやすくなり、あなたを助けてくれるでしょう。 – tw16