CSS3 滑鼠懸浮元素放大和縮小效果

antzone發表於2017-03-03

本章節分享一段程式碼例項,它實現了滑鼠懸浮元素,元素放大和縮小功能。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
/*縮放樣式程式碼*/
#box{
  width: 500px;
  margin:0 auto;
}
#long_box{
  height:281px;
  position: relative;
  border:1px solid #eee;
  overflow: hidden;
}
#long{
  position: absolute;
  width: 100%;
  height: 100%;
  -ms-transform: scale(0,0);
  -moz-transform: scale(0,0);
  -webkit-transform: scale(0,0);
  -o-transform: scale(0,0);
  transform: scale(0,0);
  background-color:#091345;
  filter:alpha(opacity=50);
  background-color: rgba(9,19,69,0.5);
  -ms-transform-origin: 50% 50%;
  -moz-transform-origin: 50% 50%;
  -webkit-transform-origin: 50% 50%;
  -o-transform-origin: 50% 50%;
  transform-origin: 50% 50%;
  -ms-transition: all 1s;
  -moz-transition: all 1s;
  -webkit-transition: all 1s;
  -o-transition: all 1s;
  transition: all 1s;
}
#box:hover #long{
  -ms-transform: scale(1,1);
  -moz-transform: scale(1,1);
  -webkit-transform: scale(1,1);
  -o-transform: scale(1,1);
  transform: scale(1,1);
}
h3{/*文字漸變IE不支援*/
  font-size: 30px;
  text-align: center;
  background-image:-webkit-gradient(linear,0 0,0 bottom, from(rgba(212,100,211,1)),to(rgba(25, 40,113,1)));
  -ms-background-clip: text;
  -moz-background-clip: text;
  -webkit-background-clip: text;
  -o-background-clip: text;
  background-clip: text;
  -ms-text-fill-color: transparent;
  -moz-text-fill-color: transparent;
  -webkit-text-fill-color: transparent;
  -o-text-fill-color: transparent;
  text-fill-color: transparent;
}
#box:hover h3{
  background-image:-webkit-gradient(linear,0 0,0 bottom,from(rgba(25,40,113,1)), to(rgba(212,100,211,1)));
}
</style>
</head>
<body>
<div id="box">
  <div id="long_box">
    <div id="long"></div>
  </div>
<h3>圖片縮放AND旋轉</h3>
</div>
</body>
</html>

相關文章