css3--background属性

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<style>
		/*1*/
		.one{
			width: 300px;
			height: 300px;
			border: 1px solid blue;
			background-color: azure;
			background-image: url(../img/beautiful01.png);
			background-repeat: no-repeat;
			background-position: center;
			background-size: contain;
			
		}
		
		/*2*/
		.two{
			width: 300px;
			height: 300px;
			border: 20px solid blue;
			padding: 20px;
			background-color: azure;
			background-image:url(../img/beautiful.jpg) ;
			background-repeat: no-repeat;
			background-clip: content-box;//剪切位置	
			background-origin: padding-box;//定位位置	
			background-position: 10px 10px;
		}
		/*3、多个*/
		.three{
			width: 300px;
			height: 300px;
			border: 20px solid blue;
			padding: 20px;
			background-image: url(../img/beautiful01.png),url(../img/beautiful.jpg);
			background-repeat: no-repeat;
			background-clip: content-box;
			background-size: 200px 300px;
			background-position:10px 10px,50px 50px ;
		}
		
		/*4、替换*/
		.four{
			width: 300px;
			height: 300px;
			border: 1px solid blue;
			background-color: azure;
			background-image: url(../img/beautiful01.png),url(../img/beautiful.jpg);
			background-repeat: no-repeat;
			background-size: 100% 100%,100% 100%;
			background-position: 0px 0px,-500px -500px;			
		}
		
	</style>
	<script>
		window.οnlοad=function  () {
		     var div=document.getElementsByTagName("div")[3];
             var positionArr=(getStyle(div,"backgroundPosition")).split(",");
             var num=0;
			 setInterval(function(){
			      if(num==positionArr.length){
				    num=0;
				  }
			      for (var i=0; i<positionArr.length; i++) {
				    if(i==num){
					  positionArr[i]="0 0";
					}else{
					  positionArr[i]="-500px -500px";
					}
			      }
                 div.style.backgroundPosition=positionArr.join(",");
				 num++
			 },3000)
		   }
			
			//获取属性
		   function getStyle (obj,attr) {
              if(window.getComputedStyle){
			    return getComputedStyle(obj,null)[attr];
			  }else{
			    return obj.currentStyle[attr];
			  }
		   }
		
	</script>
	<body>
		<div class="one"></div>
		<br/>
		<div class="two"></div>
		<br/>
		<div class="three"></div>
		<br/>
		<div class="four"></div>
	</body>
</html>



效果图


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值