1
私はフロントエンドWeb開発の初心者です。私の目標は、異なるサイズでグーグルから撮影した画像を持っているカルーセルを作ることで、カルーセルを作るので、ここでreponsivnes応答性を損なうことなく、さまざまな画像サイズの静的カルーセルを作る方法
を壊すことなく、最大の画像とこのすべての寸法を有している例です。
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img class="Image" src="http://somewhere.image1.jpg" alt="Image from google">
<div class="carousel-caption">
<h3>Title</h3>
<p>Description</p>
</div>
</div>
<div class="item">
<img class="Image" src="http://somewhere.image2.jpg" alt="Image from google">
<div class="carousel-caption">
<h3>Title</h3>
<p>Description</p>
</div>
</div>
<div class="item">
<img class="Image" src="http://somewhere.image3.jpg" alt="Image from google">
<div class="carousel-caption">
<h3>Title</h3>
<p>Description</p>
</div>
</div>
</div>
これを行うには、デフォルトまたは簡単な方法が存在しない場合、私は擬似コード以下のようなジャバスクリプト/ jQueryの関数を書きたいと思います:このCSSは助けるべき
$(document).ready(function() {
$('#myCarousel').carousel();
myFunction();
});
function myFunction() {
var biggestWidth;
var biggestHeight;
var dimensionsArr;
for each Image class object {
//get the size array
dimensionsArr = getSize(Image);
//if biggest dimenensons are null then assign the first one
if (biggestWidth = null && biggestHeight = null){
biggestWidth = dimensionsArr[0];
biggestHeight = dimensionsArr[1];
}else{
biggestWidth = ifBigger(dimensionsArr[0],biggestWidth);
biggestHeight = ifBIgger(dimensionsArr[1],biggestHeight);
}
//Next i want to display the carousel in the way it would scale
//on the device (or parent element) with the biggest image, but for all images. Ofcourse the biggest image should scale to width of the parent element of the carousel as well like it is by default
}
}
function getSize(Image image) {
var widthHeight;
Get the size of the image
//This would be an array [width, height]
return widthHeight
}
//the function determines if new dimension is bigger or old biggest
// and return the bigger one
function ifBigger(newSize,biggestSize) {
if(newSize > biggestSize) {
return newSize;
}
else() {
return biggestSize;
}
}