スクロールした位置に合わせてモーダルウィンドウとオーバーレイの表示位置を常に中央にしたいです。
pcだと常に中央に表示されるのですが、スマホで見ると画面上部に固定されてしまいます。
positionをfixedにしたり、
css
1transform: translateY(-50%) translateX(-50%); 2 -webkit- transform: translateY(-50%) translateX(-50%); 3transform: translateY(-50%) translateX(-50%); 4 -webkit- transform: translateY(-50%) translateX(-50%);
上記のコードをいれてみたりしたのですが、場所が間違っているのか上手くいきませんでした。
js内のcenterOnscrollに何か加えれば中央に表示されるでしょうか?
下記はfancy boxのcssと一部jsです。アドバイスよろしくお願いいたします。
css
1#fancybox-loading { 2 position: fixed; 3 top: 50%; 4 left: 50%; 5 width: 40px; 6 height: 40px; 7 margin-top: -20px; 8 margin-left: -20px; 9 cursor: pointer; 10 overflow: hidden; 11 z-index: 1104; 12 display: none; 13} 14 15#fancybox-loading div { 16 position: absolute; 17 top: 0; 18 left: 0; 19 width: 40px; 20 height: 480px; 21 background-image: url('fancybox.png'); 22} 23 24#fancybox-overlay { 25 position: absolute; 26 top: 0; 27 left: 0; 28 width: 100%; 29 z-index: 1100; 30 display: none; 31} 32 33#fancybox-tmp { 34 padding: 0; 35 margin: 0; 36 border: 0; 37 overflow: auto; 38 display: none; 39} 40 41#fancybox-wrap { 42 position: absolute; 43 top: 0; 44 left: 0; 45 padding: 20px; 46 z-index: 1101; 47 outline: none; 48 display: none; 49} 50 51#fancybox-outer { 52 position: relative; 53 width: 100%; 54 height: 100%; 55 background: #fff; 56} 57 58#fancybox-content { 59 width: 0; 60 height: 0; 61 padding: 0; 62 outline: none; 63 position: relative; 64 overflow: hidden; 65 z-index: 1102; 66 border: 0px solid #fff; 67} 68 69#fancybox-hide-sel-frame { 70 position: absolute; 71 top: 0; 72 left: 0; 73 width: 100%; 74 height: 100%; 75 background: transparent; 76 z-index: 1101; 77} 78 79#fancybox-close { 80 position: absolute; 81 top: -15px; 82 right: -15px; 83 width: 30px; 84 height: 30px; 85 background: transparent url('fancybox.png') -40px 0px; 86 cursor: pointer; 87 z-index: 1103; 88 display: none; 89} 90 91#fancybox-img { 92 width: 100%; 93 height: 100%; 94 padding: 0; 95 margin: 0; 96 border: none; 97 outline: none; 98 line-height: 0; 99 vertical-align: top; 100} 101 102#fancybox-frame { 103 width: 100%; 104 height: 100%; 105 border: none; 106 display: block; 107} 108 109#fancybox-left, #fancybox-right { 110 position: absolute; 111 bottom: 0px; 112 height: 100%; 113 width: 35%; 114 cursor: pointer; 115 outline: none; 116 background: transparent url('blank.gif'); 117 z-index: 1102; 118 display: none; 119} 120 121#fancybox-left { 122 left: 0px; 123} 124 125#fancybox-right { 126 right: 0px; 127} 128 129#fancybox-left-ico, #fancybox-right-ico { 130 position: absolute; 131 top: 50%; 132 left: -9999px; 133 width: 30px; 134 height: 30px; 135 margin-top: -15px; 136 cursor: pointer; 137 z-index: 1102; 138 display: block; 139} 140 141#fancybox-left-ico { 142 background-image: url('fancybox.png'); 143 background-position: -40px -30px; 144} 145 146#fancybox-right-ico { 147 background-image: url('fancybox.png'); 148 background-position: -40px -60px; 149} 150 151#fancybox-left:hover, #fancybox-right:hover { 152 visibility: visible; /* IE6 */ 153} 154 155#fancybox-left:hover span { 156 left: 20px; 157} 158 159#fancybox-right:hover span { 160 left: auto; 161 right: 20px; 162} 163 164.fancybox-bg { 165 position: absolute; 166 padding: 0; 167 margin: 0; 168 border-left-width: 0; 169 border-right-width: 0; 170 border-bottom: 0; 171 border-top-width: 0; 172 width: 20px; 173 height: 20px; 174 z-index: 1001; 175} 176 177#fancybox-bg-n { 178 top: -20px; 179 left: 0; 180 width: 100%; 181 background-image: url('fancybox-x.png'); 182} 183 184#fancybox-bg-ne { 185 top: -20px; 186 right: -20px; 187 background-image: url('fancybox.png'); 188 background-position: -40px -162px; 189} 190 191#fancybox-bg-e { 192 top: 0; 193 right: -20px; 194 height: 100%; 195 background-image: url('fancybox-y.png'); 196 background-position: -20px 0px; 197} 198 199#fancybox-bg-se { 200 bottom: -20px; 201 right: -20px; 202 background-image: url('fancybox.png'); 203 background-position: -40px -182px; 204} 205 206#fancybox-bg-s { 207 bottom: -20px; 208 left: 0; 209 width: 100%; 210 background-image: url('fancybox-x.png'); 211 background-position: 0px -20px; 212} 213 214#fancybox-bg-sw { 215 bottom: -20px; 216 left: -20px; 217 background-image: url('fancybox.png'); 218 background-position: -40px -142px; 219} 220 221#fancybox-bg-w { 222 top: 0; 223 left: -20px; 224 height: 100%; 225 background-image: url('fancybox-y.png'); 226} 227 228#fancybox-bg-nw { 229 top: -20px; 230 left: -20px; 231 background-image: url('fancybox.png'); 232 background-position: -40px -122px; 233} 234
js
1b.fn.fancybox.defaults={padding:10,margin:40,opacity:false,modal:false,cyclic:false,scrolling:"auto",width:560,height:340,autoScale:true,autoDimensions:true,centerOnScroll:false,ajax:{},swf:{wmode:"transparent"},hideOnOverlayClick:true,hideOnContentClick:false,overlayShow:true,overlayOpacity:0.7,overlayColor:"#0E0E0F",titleShow:true,titlePosition:"float",titleFormat:null,titleFromAlt:false,transitionIn:"fade",transitionOut:"fade",speedIn:300,speedOut:300,changeSpeed:300,changeFade:"fast",easingIn:"swing", 2easingOut:"swing",showCloseButton:true,showNavArrows:true,enableEscapeButton:true,enableKeyboardNav:true,onStart:function(){},onCancel:function(){},onComplete:function(){$.fancybox.center();},onCleanup:function(){},onClosed:function(){},onError:function(){}};b(document).ready(function(){b.fancybox.init()})})(jQuery);

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/04/17 04:54 編集