Here是一個解決方案的小提琴。點擊一個圖像(彩色塊)打開myCanvas
並填充選定的圖像。點擊myCanvas
中的任意位置將其隱藏並選擇其他圖片。
HTML:
<div id="wrapper">
<div class="images_box">
<a><img style="background: red;" /></a>
<a><img style="background: blue;" /></a>
<a><img style="background: green;" /></a>
<a><img style="background: black;" /></a>
<a><img style="background: pink;" /></a>
</div>
<div class="myCanvas"></div>
</div>
CSS:
* {
padding: 0px;
margin: 0px;
}
#wrapper {
position: relative;
width: 80%;
margin-right: auto;
margin-left: auto;
height: 300px;
/*background: #123;*/
}
.images_box {
width: 100%;
height: 60px;
}
img {
display: inline-block;
height: 50px;
width: 50px;
margin: 0px;
padding: 5px;
}
.myCanvas {
display: none;
width: 100%;
height: 300px;
position: absolute;
top: 0px;
left: 0px;
background: #999;
}
的JavaScript:
$(document).ready(function() {
$('a').click(function() {
$('.myCanvas').fadeIn();
$('.myCanvas').html($(this).html());
$('.myCanvas').children().css('display', 'block');
$('.myCanvas').children().css({
'margin-left': 'auto',
'margin-right': 'auto'
});
var topMargin = 125;
$('.myCanvas').children().css('margin-top', topMargin);
});
$('.myCanvas').click(function() {
$('.myCanvas').fadeOut();
});
});
它採用圖像(將html複製到myCanvas
)然後居中。
先生,你如何使它不會從背頁消失。我嘗試了使用2個圖像。每當我點擊圖片,它就會從網站上消失,並顯示在中間。謝謝 – user1998735
更新的小提琴和代碼,這應該做你想找的。請接受我的標題編輯,因爲它使問題更清晰,解決方案更有價值。 – mattdlockyer
非常謝謝你,馬特先生。它現在的作品... – user1998735