html jQuery Mobile的卡片UI

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html jQuery Mobile的卡片UI相关的知识,希望对你有一定的参考价值。

// function to create the cards
function createCards() {
	// declaring some variables
	var exampleBlockA = $('#exampleBlockA'), // cache the selector of the element, increases performance
		exampleBlockB = $('#exampleBlockB'), // cache the selector of the element, increases performance
		exampleBlockC = $('#exampleBlockC'), // cache the selector of the element, increases performance
		i,
		j = 1,
		tag,
		
		// the cards, in this example in an array
		imagename = ["Image1", "Image2", "Image3"],
		imagesource = ["./images/image1.jpg", "./images/image2.jpg", "./images/image3.jpg"],
		titlecard = ["Image!", "Image!", "Image!"],
		titleimage = ["Title", "Title", "Title"],
		text = ["Lorem ipsum part 1...", "Lorem ipsum part 2...", "Lorem ipsum part 3..."];
 
	// emptying the current grid
	exampleBlockA.empty();
	exampleBlockB.empty();
	exampleBlockC.empty();
 
	// the loop to get the values from the arrays
	for (i = 0; i < 3; i = i + 1) {
		tag = '<div class="card" id="card' + i + '">'; // start building the tag for the card
		if (imagename[i] !== null && imagesource[i] !== null) {
			tag = tag + '<div class="card-image"><img alt="' + imagename[i] + '" src="' + imagesource[i] + '" />'; // insert imagesource and imagename if they exists
			if (titleimage[i] !== null) {
				tag = tag + '<h2>' + titleimage[i] + '</h2>'; // insert titleimage if it exists
			}
			tag = tag + '</div>'; // close the image part of the card
		}
		if (titlecard[i] !== null) {
			tag = tag + '<h1>' + titlecard[i] + '</h1>'; // insert titlecard if it exists
		}
		if (text[i] !== null) {
			tag = tag + '<p>' +  text[i] + '</p>'; // insert text in the card if it exists
		}
		tag = tag + '</div>'; // end the card building
		
		/*	You will need to create cards in a special order.
			The first 1/3 of the cards are placed in block A.
			The second 1/3 of the cards are placed in block B.
			The last 1/3 of the cards are placed in block C.
			
			This will make sure that the cards will fill white spots
			when the screen is changing orientation and/or size.
			
			When you create new block for every card you would get
			an interface that is lined like a table.
		*/
		if (i < (result.rows.length / 3)) {
			exampleBlockA.append(tag);
		} else if (i < ((result.rows.length / 3) * 2)) {
			exampleBlockB.append(tag);
		} else if (i <= ((result.rows.length / 3) * 3)) {
			exampleBlockC.append(tag);
		}
		
		// add a press effect to the card
		pressEffectCard('card' + i);
	}
}
 
// press effect card ui
function pressEffectCard(x) {
	var id = $("#" + x); // cache the selector of the element, increases performance
	id.off('touchstart').on('touchstart', function () {
		id.addClass("holoPressEffectDiv");
	});
	id.off('touchend').on('touchend', function () {
		id.removeClass("holoPressEffectDiv");
	});
	id.off('touchmove').on('touchmove', function () {
		id.removeClass("holoPressEffectDiv"); // to remove the press effect when there is a scroll detected in stead of a tap
	});
}
.card {
  background: #FFF;
  border: 1px solid #AAA;
  box-shadow: 0px 2px 3px 0px #AAA;
  padding: 0px;
  margin-top: 15px;
  margin-right: 7.5px;
  margin-bottom: 15px;
  margin-left: 7.5px;
  overflow: hidden;
  border-radius: 3px;
}
.card h1 {
  margin: 0px;
  padding: 10px;
  padding-bottom: 0px;
}
.card p {
  margin: 0px;
  padding: 10px;
}
.card-image {
  width: 100%;
  height: 200px;
  padding: 0px;
  margin: 0px;
  background-position: center;
  background-repeat: no-repeat;
  position: relative;
  overflow: hidden;
}
.card-image .banner {
  height: 50px;
  width: 50px;
  top: 0px;
  right: 0px;
  background-position: top right;
  background-repeat: no-repeat;
  background-image: url('../images/new.png');
  position: absolute;
}
.card-image h1, 
.card-image h2, 
.card-image h3, 
.card-image h4, 
.card-image h5, 
.card-image h6 {
  position: absolute;
  bottom: 0px;
  width: 100%;
  color: white;
  background: rgba(0,0,0,0.65);
  margin: 0px;
  padding: 6px;
  border: none;
}
div.holoPressEffectDiv {
	background-color: #CCCCCC;
}
<div class="ui-grid-b ui-responsive">
 <div class="ui-block-a">Block A</div>
 <div class="ui-block-b">Block B</div>
 <div class="ui-block-c">Block C</div>
</div>
<div class="ui-grid-b ui-responsive">
 <div class="ui-block-a" id="exampleBlockA"></div>
 <div class="ui-block-b" id="exampleBlockB"></div>
 <div class="ui-block-c" id="exampleBlockC"></div>
</div>
<div class="card">
	<h2>Card Title</h2>
	<p>Lorem ipsum...</p>
</div>
<div class="card">
	<div class="card-image">
		<img alt="home" src="./images/image.png" />
		<h2>Card Title</h2>
	</div>
	<p>Lorem ipsum...</p>
</div>
<div class="card">
	<div class="card-image">
		<img alt="home" src="./images/image.png" />
		<h2>Card Title</h2>
	</div>
	<h1>Text Title</h1>
	<p>Lorem ipsum...</p>
</div>
<div class="card">
	<div class="card-image">
		<img alt="home" src="./images/image.png" />
		<div class="banner"></div>
		<h2>Card Title</h2>
	</div>
	<p>Lorem ipsum...</p>
</div>

以上是关于html jQuery Mobile的卡片UI的主要内容,如果未能解决你的问题,请参考以下文章

jquery-ui-map 与新版本的 jquery mobile 和 jquery

Jquery Mobile学习总结

如何使用 jQuery-mobile 开发看起来适合 Android 的 UI?

jquery mobile ui无法在移动设备上运行

jquery , jquery ui 和 jquery mobile 如何组合在一起

jQuery Mobile 表单输入元素