Blogger Information
Blog 48
fans 3
comment 1
visits 37481
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Jquery里如何进行样式操作——2018年4月6日
JackBlog
Original
565 people have browsed it

主要内容:

1、自定义属性操作【attr();removeAttr()】

2、原生固有属性操作【prop();removeProp()】

3、自定义数据属性操作【data()】

4、样式操作【css()】


QQ截图20180406231601.jpg

实例

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			.container{
				width: 1000px;
				margin: auto;
			}
			.container .main{

				height: 600px;
				overflow: hidden;
			}
			.main .left{
				width: 33%;
				height: 600px;
				background-color:  #FF8C00;
				float: left;
			}
			.main .right{
				width: 33%;
				height: 600px;
				background-color:  dodgerblue;
				float: right;
			}
			.main .center{
				height: 600px;
				margin-left: 33.1%;
				margin-right: 33.1%;
				background-color: #8A2BE2;
			}
				.phtitle{
				text-align: center;
				font-size: 1.5em;
				font-weight: bold;
				padding: 10px;
			}
			.ph ul{
				margin: 0;
				padding: 0;
				width: 100%;

			}
			.ph ul li{
				height: 40px;
				line-height: 40px;
				text-align: left;
				list-style-type:  none;
				margin: 10px;
				border-bottom: 1px dotted #DCDCDC;
			}
			.ph ul li:hover{
				height: 60px;
				line-height: 60px;
				background-color:  #FF7F50;
			}
			.ph ul li span{
				display: inline-block;
				width: 20px;

			}
		</style>
	</head>
	<body>

			<div class="container">

				<div class="top">
					<img src="../../img/logo.png" alt="" />
				</div>
				<div class="main">
					<div class="left">
						<div class="phtitle">今日排行</div>
						<div class="ph">
							<ul>
								<li>2</li>
								<li>a</li>
								<li>sdf</li>
								<li>sdg</li>
								<li>sdf</li>
								<li>sgdf</li>
								<li>sdf</li>
								<li>sdf</li>
								<li>sdf</li>
								<li>gfd</li>

							</ul>
						</div>
					</div>
					<div class="right">
						<div class="phtitle">七日排行</div>
						<div class="ph">
							<ul>
								<li></li>
								<li></li>
								<li></li>
								<li></li>
								<li></li>
								<li></li>
								<li></li>
								<li></li>
								<li></li>
								<li></li>
							</ul>
						</div>
					</div>
					<div class="center">
						<div class="phtitle">昨日排行</div>
						<div class="ph">
							<ul>
								<li></li>
								<li></li>
								<li></li>
								<li></li>
								<li></li>
								<li></li>
								<li></li>
								<li></li>
								<li></li>
								<li></li>
							</ul>
						</div>
					</div>
				</div>
			</div>
	</body>
</html>

<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>

<script type="text/javascript">
		$('body').attr('style','background-color:  #E4EBEC;')
	$('body').css('color','#fff')
	$('.top').css({
		'width':'100%',
		'text-align':'center',

	})

$('.top').children('img').width(280)
$('.top').children('img').height(180)



	var ul = $('.ph').children('ul')
	var li1=$(ul[0]).children('li')
	var li2=$(ul[1]).children('li')
	var li3=$(ul[2]).children('li')
		for (var i=0;i<10;i++) {
			var html1nr=''
			var html2nr=''
			var html3nr=''
			var phnum=''
			var sjnum1=Math.floor(Math.random()*10)
			var sjnum2=Math.floor(Math.random()*10)
			var sjnum3=Math.floor(Math.random()*10)
			var pic = Array('../../img/up1.jpg','../../img/up2.jpg','../../img/up3.jpg','../../img/up4.jpg','../../img/up5.jpg','../../img/up6.jpg','../../img/up7.jpg','../../img/up8.jpg','../../img/up9.jpg','../../img/up10.jpg')
			var picurl1 = '<img src="'+pic[sjnum1]+'">'
			var picurl2 = '<img src="'+pic[sjnum2]+'">'
			var picurl3 = '<img src="'+pic[sjnum3]+'">'
phnum = parseInt(i+1)
			if(i==0){

			html1nr = picurl1
			html2nr = picurl2
			html3nr = picurl3

			$(li1[i]).html(html1nr+'用户昵称'+phnum)
			$(li2[i]).html(html2nr+'用户昵称'+phnum)
			$(li3[i]).html(html3nr+'用户昵称'+phnum)
			}else{


			html1nr = '<span>'+phnum+'</span>'
			html1nr += picurl1
			html2nr = '<span>'+phnum+'</span>'
			html2nr += picurl2
			html3nr = '<span>'+phnum+'</span>'
			html3nr += picurl3

			$(li1[i]).html(html1nr+'用户昵称'+phnum)
			$(li2[i]).html(html2nr+'用户昵称'+phnum)
			$(li3[i]).html(html3nr+'用户昵称'+phnum)
			}
		}

	$('li img').css({'width':'30px','border-radius':'50%','margin':'0 10px'})

$('ul').children('li:first-child').css({'color':'red','font-size':'1.5em','text-align':'center'})
li22 = $('ul').children('li:nth-child(1)').position()
var theli1 = $(li1[0]).offset()
console.log('左边'+theli1.left+'  顶边'+theli1.top)
console.log('左边'+li22.left+'  顶边'+li22.top)
</script>

运行实例 »

点击 "运行实例" 按钮查看在线实例

QQ截图20180407190557.jpg

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post