Blogger Information
Blog 20
fans 0
comment 1
visits 14328
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
atter()和css()的使用2018年4月4日
抗太阳的博客
Original
787 people have browsed it

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>attr()和css()的用法</title>
	<style type="text/css">
	body{
		text-align: center;
		margin: 30px auto;
	}
	.box1{
		width: 200px;
		height: 200px;
		background-color: #e55555;
		margin: 30px auto;
		position: relative;
	}
	.box2{
		width: 100px;
		height: 100px;
		background-color: yellow;
		border-radius: 50%;
		position: relative;
		top: 30px;
		left: 50px;
	}
	</style>
</head>
<body>
<img src="images/1.jpg" alt="沙漠" title="图片" id="pic" data-nation="小明">
<div class="box1"><div class="box2"></div></div>

</body>
<script type="text/javascript" src="js/jquery-3.3.1.js"></script>
<script type="text/javascript">
// attr()属性的获取与设置
var res = $('img').attr('style','border-radius:10px;box-shadow:2px 2px 4px #ccc')
// css()设置样式
var res = $('img').css('width',400)
var res = $('img').css({
	'width':'450','box-shadow':'4px 4px 8px #ee0000'
})
// jquery针对宽高样式有两个专用方法
var res = $('img').width(300)
// 支持运算符的简写
var res =$('img').width('+=50')
var res =$('img').width()

var res = $('img').height(150)
// 支持运算符的简写
var res =$('img').height('+=50')
var res =$('img').height()

// 获取元素的位置:offset(),返回的是一个对象
var res=$('img').offset().left
var res=$('img').offset().top
// 查看绝对定位的偏移量
var res =$('.box2').position().left
var res =$('.box2').position().top
console.log(res)

</script>
</html>

运行实例 »

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

微信图片_20180408081800.png

Correction status:Uncorrected

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