您好,欢迎来到源码搜藏!分享精神,快乐你我!提示:担心找不到本站?在百度搜索“源码搜藏”,网址永远不丢失!
  • 首 页
  • 在线工具
  • 当前位置:首页 > 网页特效 > 图片特效 >

    CSS3图片放大缩小代码特效

    时间:2013-12-19 08:58 来源:互联网 作者:源码搜藏 浏览:收藏 挑错 推荐 打印

    运行代码保存代码复制代码 提示:您可以先修改部分代码再运行,保存代码功能在Firefox下无效。
    • 再次与大家分享一款基于纯CSS3代码的图片放大、图片缩小显示特效,带动画效果,测试请使用IE9,火狐或Chrome,CSS3的动画处理能力很强,传统的CSS是无法比拟的。本款动画效果类似Flash,但与Flash不粘边,有兴趣请参阅代码吧。
    • <!DOCTYPE html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>CSS3图片放大缩小效果[www.codesocang.com]</title>
      <style>
      .textboxstyle {
      font-family:Arial;
      font-size:16pt;
      color:black;
      text-align:center;
      vertical-align:top;
      }
      .textboxbackgroundstyle {
      background-color:white;
      padding:5px;
      -moz-border-radius-topleft: 15px;
      -moz-border-radius-bottomright: 15px;
      -webkit-border-top-left-radius: 15px;
      -webkit-border-bottom-right-radius: 15px;
      border-top-left-radius: 15px;
      border-bottom-right-radius: 15px;
      }
      .curveandshadowstyle {
      -moz-box-shadow: 5px 5px 8px #818181;
      -moz-border-radius-topleft: 25px;
      -moz-border-radius-bottomright: 25px;
      -webkit-box-shadow: 5px 5px 8px #818181;
      -webkit-border-top-left-radius: 25px;
      -webkit-border-bottom-right-radius: 25px;
      box-shadow: 5px 5px 5px #818181;
      border-top-left-radius: 25px;
      border-bottom-right-radius: 25px;
      filter: progid:DXImageTransform.Microsoft.Shadow(Strength=5, Direction=135, Color='#818181');
      border-style:solid;
      border-width:1px;
      border-color:white;
      }
      </style>
      <script>
      var imgurl= new Array()
      var message= new Array()
      var thislink= new Array()
      imgurl[0]="http://www.codefans.net/jscss/demoimg/201312/300x180bluefish.jpg"
      imgurl[1]="http://www.codefans.net/jscss/demoimg/201312/300x180bonbons.jpg"
      message[0]="Let's go fishing today"
      message[1]="You are even sweeter"
      thislink[0]="#"
      thislink[1]="#"
      var imgwidth=300
      var imgheight=180
      var stillstand=2.5
      var opacitystrength=60
      var tmr
      var step=10
      var i=imgwidth
      var i_imgurl=0
      stillstand*=1000
      var preloadedimages=new Array()
      for (iii=0;iii<imgurl.length;iii++){
      preloadedimages[iii]=new Image()
      preloadedimages[iii].src=imgurl[iii]
      }
      function shrinkpic() {
      document.getElementById("textbox").innerHTML=""
      if (i>0) {
      i-=step
      document.getElementById("picdiv").style.width=i+"px"
      document.getElementById("picdiv").style.height=i*(imgheight/imgwidth)+"px"
      document.getElementById("picdiv").style.left=imgwidth/2-(i/2)+"px"
      document.getElementById("picdiv").style.top=(imgwidth/2-(i/2))*(imgheight/imgwidth)+"px"
      tmr=setTimeout("shrinkpic()",20)
      }
      else {
      i_imgurl++
      if (i_imgurl>=imgurl.length) {
      i_imgurl=0
      }
      document.getElementById("picdiv").style.background="url("+imgurl[i_imgurl]+")"
      i=1
      tmr=setTimeout("enlargepic()",20)
      }
      }
      function enlargepic() {
      if (i<=imgwidth) {
      i+=step
      document.getElementById("picdiv").style.width=i+"px"
      document.getElementById("picdiv").style.height=i*(imgheight/imgwidth)+"px"
      document.getElementById("picdiv").style.left=imgwidth/2-(i/2)+"px"
      document.getElementById("picdiv").style.top=(imgwidth/2-(i/2))*(imgheight/imgwidth)+"px"
      tmr=setTimeout("enlargepic()",20)
      }
      else {
      i=imgwidth
      showmessage()
      }
      }
      function showmessage() {
      document.getElementById("textbox").innerHTML='<span class="textboxbackgroundstyle">'+message[i_imgurl]+'</span>'
      tmr=setTimeout("shrinkpic()",stillstand)
      }
      function gotothislink(){
      document.location.href=thislink[i_imgurl]
      }
      document.write('<div id="roof" style="position:relative;width:'+imgwidth+'px;height:'+imgheight+'px;">')
      document.write('<div id="picdiv" class="curveandshadowstyle" style="position:absolute;background:url('+imgurl[0]+');width:'+imgwidth+'px;height:'+imgheight+'px;top:0px;left:0px;"></div>')
      document.write('<div id="tt" onClick="gotothislink()" style="position:absolute;width:'+imgwidth+'px;height:'+imgheight+'px;top:0px;left:0px;filter:alpha(opacity='+opacitystrength+');opacity:'+(opacitystrength/100)+';cursor:pointer;"><table width='+imgwidth+' height='+imgheight+'><tr><td id="textbox" class="textboxstyle"><span class="textboxbackgroundstyle">'+message[0]+'</span></td></tr></table></div>')
      document.write('</div>')
      window.onload=shrinkpic
      </script>
      </body>
      </html>

    CSS3图片放大缩小代码特效由源码搜藏网整理,转载请注明出处http://www.codesocang.com/texiao/pic/6518.html
    标签:网站源码