JS實現(xiàn)圖片高斯模糊切換效果的焦點圖實例
焦點圖相信對大家來說都不陌生,本文給大家分享的是一種圖片高斯模糊切換效果的焦點圖,下面話不多說了,來看看實現(xiàn)的效果圖和實例代碼吧。
效果圖

實例代碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無標(biāo)題文檔</title>
<style>
@-webkit-keyframes show
{
0%{
opacity:1;
-webkit-transform:scale(1);
}
100%
{
opacity:.1;
-webkit-transform:scale(3);
}
}
body{ background:#e8d0ca;}
#wrap{width:600px; margin:100px auto;border:2px solid #000; position:relative;}
#list{ position:relative; height:310px;margin:0;padding:0; list-style:none;}
#list li{ width:281px;height:310px; background:url(http://cdn.attach.qdfuns.com/notes/pics/201701/17/113914zaxalfffaylelyxd.png) no-repeat; position:absolute;top:0; transition:.6s;}
#list span{ width:100%;height:100%; display:block;transition:.6s;}
#list li:nth-of-type(1){ left:0;z-index:1; -webkit-transform:scale(0.8);opacity:0.6;}
#list li:nth-of-type(1) span{ background:url(http://cdn.attach.qdfuns.com/notes/pics/201701/17/113914zfkmqfb0zzummnhy.png); opacity:1;}
#list li:nth-of-type(2){ left:calc(50% - 140px);background-image:url(http://cdn.attach.qdfuns.com/notes/pics/201701/17/113913nvvkf5pf4f77x55k.png);z-index:2; opacity:1;}
#list li:nth-of-type(2) span{ background:url(http://cdn.attach.qdfuns.com/notes/pics/201701/17/113914cx8x8z8ldfgckpmf.png); opacity:0;}
#list li:nth-of-type(3){ left:calc(100% - 281px);background-image:url(http://cdn.attach.qdfuns.com/notes/pics/201701/17/113914zhou55z6tlru25lu.png);z-index:1;-webkit-transform:scale(0.8); opacity:0.6;}
#list li:nth-of-type(3) span{ background:url(http://cdn.attach.qdfuns.com/notes/pics/201701/17/113914sofg7wja0c0cowjv.png); opacity:1;}
.btn{width:18px;height:29px; position:absolute;top:130px;z-index:10; cursor:pointer;}
.btn span{ position:absolute;left:0;top:0; background:inherit; width:100%;height:100%; transition:.5s;}
.btn:hover span:nth-of-type(1){-webkit-animation:show 2s infinite; }
.btn:hover span:nth-of-type(2){-webkit-animation:show 2s 1s infinite; }
#prev{ left:80px; background:url(http://cdn.attach.qdfuns.com/notes/pics/201701/17/113915d96e0acuyjccybcb.png) no-repeat;}
#next{ right:80px; background:url(http://cdn.attach.qdfuns.com/notes/pics/201701/17/113915kfhwnrawaeaibf6a.png) no-repeat;}
</style>
</head>
<body>
<div id="wrap">
<ul id="list">
<li>
<span></span>
</li>
<li>
<span></span>
</li>
<li>
<span></span>
</li>
</ul>
<div id="prev" class="btn">
<span></span>
<span></span>
</div>
<div id="next" class="btn">
<span></span>
<span></span>
</div>
</div>
<script>
window.onload=function()
{
var oList=document.getElementById("list");
var aLi=oList.children;
var oPrev=document.getElementById("prev");
var oNext=document.getElementById("next");
var arr=[];
//arr.unshift(arr.pop());把最后一個刪除添加到數(shù)組第一個
//arr.push(arr.shift());把第一個刪除添加到數(shù)組第一個
//獲取li的信息
for(var i=0;i<aLi.length;i++)
{
var oSpan=aLi[i].children[0];
arr[i]={left:getStyle(aLi[i],"left"),opacity:getStyle(aLi[i],"opacity"),scale:getStyle(aLi[i],"-webkit-transform"),zIndex:getStyle(aLi[i],"z-index"),alpha:getStyle(oSpan,"opacity")};
}
oPrev.onclick=function()
{
arr.unshift(arr.pop());
toStyle();
};
oNext.onclick=function()
{
arr.push(arr.shift());
toStyle();
};
function toStyle()
{
for(var i=0;i<aLi.length;i++)
{
var oSpan=aLi[i].children[0];
aLi[i].style.left=arr[i].left;
aLi[i].style.opacity=arr[i].opacity;
aLi[i].style.WebkitTransform=arr[i].scale;
aLi[i].style.zIndex=arr[i].zIndex;
oSpan.style.opacity=arr[i].alpha;
}
}
};
function getStyle(obj,attr)
{
if( obj.currentStyle){
return obj.currentStyle[attr];
}
return getComputedStyle(obj)[attr];
}
</script>
</body>
</html>
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript切換特效與技巧總結(jié)》、《JavaScript查找算法技巧總結(jié)》、《JavaScript動畫特效與技巧匯總》、《JavaScript錯誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運算用法總結(jié)》
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。
相關(guān)文章
JavaScript必知必會(三) String .的方法來自何方
這篇文章主要介紹了JavaScript必知必會(三) String .的方法來自何方的相關(guān)資料,非常不錯具有參考借鑒價值,需要的朋友可以參考下2016-06-06
基于JS實現(xiàn)html中placeholder屬性提示文字效果示例
這篇文章主要介紹了基于JS實現(xiàn)html中placeholder屬性提示文字效果,涉及javascript事件響應(yīng)及頁面元素屬性動態(tài)操作相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2018-04-04
JavaScript為事件句柄綁定監(jiān)聽函數(shù)實例詳解
這篇文章主要介紹了JavaScript為事件句柄綁定監(jiān)聽函數(shù)的方法,結(jié)合實例詳細(xì)分析了常見的事件句柄綁定監(jiān)聽函數(shù)的實現(xiàn)技巧,并實例講解了跨瀏覽器的實現(xiàn)方法,需要的朋友可以參考下2015-12-12
JavaScript正則函數(shù)中test和match的區(qū)別解析
在javascript中,用于檢測一個字符串是否匹配某個模式用的比較多的就是test和match方法。,這篇文章主要介紹了js正則函數(shù)中test和match的區(qū)別,需要的朋友可以參考下2022-11-11
highcharts.js數(shù)據(jù)綁定方式代碼實例
這篇文章主要介紹了highcharts.js數(shù)據(jù)綁定方式代碼實例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-11-11

