站长资源网络编程

CSS+jQuery实现的一个放大缩小动画效果

整理:jimmy2026/9/4浏览2
简介今天帮朋友写了一些代码,自己觉得写着写着,好几个版本以后,有点满意,于是就贴出来。 都是定死了的。因为需求就只有4个元素。如果是要用CSS的class来处理,那就需要用到CSS3动画了。 复制代码 代码如下: CSS+jQu</div> <div class="news_infos"><div id="MyContent">今天帮朋友写了一些代码,自己觉得写着写着,好几个版本以后,有点满意,于是就贴出来。 <BR>都是定死了的。因为需求就只有4个元素。如果是要用CSS的class来处理,那就需要用到CSS3动画了。 <BR><U>复制代码</U> 代码如下: <BR><!DOCTYPE html> <BR><html> <BR><head> <BR><title> CSS+jQuery动画效果 </title> <BR><meta name="Generator" content="EditPlus"> <BR><meta name="Author" content="铁锚"> <BR><style> <BR>body{ <BR>z-index: 0; <BR>width: 100%; <BR>min-height: 400px; <BR>} <BR>.pages{ <BR>position: absolute; <BR>} <BR>.current{ <BR>position: absolute; <BR>z-index: 12 !important; <BR>left: 0px !important; <BR>} <BR>.page1{ <BR>background-color: #a5cfff; <BR>z-index: 1; <BR>width: 300px; <BR>height:280px; <BR>top: 100px; <BR>left: 0px; <BR>} <BR>.page2{ <BR>background-color: #b1ca54; <BR>z-index: 2; <BR>width: 250px; <BR>height:270px; <BR>top: 160px; <BR>left: 0px; <BR>} <BR>.page3{ <BR>background-color: #c2c6c9; <BR>z-index: 3; <BR>width: 200px; <BR>height:260px; <BR>top: 220px; <BR>left: 0px; <BR>} <BR>.page4{ <BR>background-color: #ef9e9c; <BR>z-index: 4; <BR>width: 150px; <BR>height:250px; <BR>top: 250px; <BR>left: 0px; <BR>} <BR></style> <BR><script type="text/javascript" src="/UploadFiles/2021-04-02/jquery-1.9.1.min.js"><script> <BR>$(function(){ <BR>// 增长 <BR>function increase($div,e){ <BR>var style = $div.attr("style"); <BR>$div.addClass("current").attr("styleold",style); <BR>// <BR>$div.stop(); <BR>$div.animate({ <BR>opacity:0.9, <BR>width:"400px", <BR>height: "400px", <BR>top: "100px", <BR>left: "0px" <BR>},600) <BR>.animate({ <BR>opacity:1.0 <BR>},30); <br><br>e.stopPropagation(); <BR>return false; <BR>}; <BR>// 还原 <BR>function resize(e){ <BR>// 所有的都移除 <BR>var $page1 = $(".current.page1") ; <BR>$page1.stop(); <BR>$page1.animate({ <BR>opacity:1.0, <BR>width:"300px", <BR>height: "280px", <BR>top: "100px", <BR>left: "0px" <BR>},600,null,function(){ <BR>$page1.removeClass("current").attr("style",""); <BR>}); <br><br>var $page2 = $(".current.page2") ; <BR>$page2.stop(); <BR>$page2.animate({ <BR>opacity:1.0, <BR>width:"250px", <BR>height: "270px", <BR>top: "160px", <BR>left: "0px" <BR>},600,null,function(){ <BR>$page2.removeClass("current").attr("style",""); <BR>}); <br><br>var $page3 = $(".current.page3") ; <BR>$page3.stop(); <BR>$page3.animate({ <BR>opacity:1.0, <BR>width:"200px", <BR>height: "260px", <BR>top: "220px", <BR>left: "0px" <BR>},600,null,function(){ <BR>$page3.removeClass("current").attr("style",""); <BR>}); <br><br>var $page4 = $(".current.page4") ; <BR>$page4.stop(); <BR>$page4.animate({ <BR>opacity:1.0, <BR>width:"150px", <BR>height: "250px", <BR>top: "250px", <BR>left: "0px" <BR>},600,null,function(){ <BR>$page4.removeClass("current").attr("style",""); <BR>}); <br><br>e.stopPropagation(); <BR>return false; <BR>}; <BR>// <BR>$("#button1").unbind("mouseover").bind("mouseover",function(e){ <BR>// <BR>var $page1 = $(".page1"); <BR>// 添加特定的 <BR>return increase($page1,e); <br><br>}).unbind("mouseout").bind("mouseout",function(e){ <BR>return resize(e); <br><br>}); <BR>// <BR>$("#button2").unbind("mouseover").bind("mouseover",function(e){ <BR>// <BR>var $page2 = $(".page2"); <BR>// 添加特定的 <BR>return increase($page2,e); <br><br>}).unbind("mouseout").bind("mouseout",function(e){ <BR>return resize(e); <BR>}); <BR>// <BR>$("#button3").unbind("mouseover").bind("mouseover",function(e){ <BR>// <BR>var $page3 = $(".page3"); <BR>// 添加特定的 <BR>return increase($page3,e); <br><br>}).unbind("mouseout").bind("mouseout",function(e){ <BR>return resize(e); <BR>}); <BR>// <BR>$("#button4").unbind("mouseover").bind("mouseover",function(e){ <BR>// <BR>var $page4 = $(".page4"); <BR>// 添加特定的 <BR>return increase($page4,e); <br><br>}).unbind("mouseout").bind("mouseout",function(e){ <BR>return resize(e); <BR>}); <br><br>// <BR>$(".pages").unbind("mouseover").bind("mouseover",function(e){ <BR>// <BR>var $this = $(this); <BR>// 添加特定的 <BR>return increase($this,e); <BR>}).unbind("mouseout").bind("mouseout",function(e){ <BR>// 所有的都移除 <BR>return resize(e); <BR>}); <BR>// <BR>$("body").click(function(e){ <BR>// 所有的都移除 <BR>return resize(e); <BR>}); <BR>}); <BR></script> <BR></head> <br><br><body> <BR><div class="pages page1">page1</div> <BR><div class="pages page2">page2</div> <BR><div class="pages page3">page3</div> <BR><div class="pages page4">page4</div> <br><br><div style="background-color: #a5cfff;"> <BR><button id="button1">第一页</button> <BR><button id="button2">第2页</button> <BR><button id="button3">第3页</button> <BR><button id="button4">第4页</button> <BR></div> <BR></body> <BR></html> <BR></div> </div> </div> <div class="share"> </div> <div class="nextinfo"> <p>上一篇:<a href="http://m.paidiu.com/show/1/121579.html" title="JS 实现导航栏悬停效果(续)">JS 实现导航栏悬停效果(续)</a></p> <p>下一篇:<a href="http://m.paidiu.com/show/1/121581.html" title="JavaScript中访问节点对象的方法有哪些如何使用">JavaScript中访问节点对象的方法有哪些如何使用</a></p> </div> <div class="otherlink"> <h2>最新资源</h2> <ul> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/619123.html" one-link-mark="yes" title="群星《奔赴!万人现场 第2期》[FLAC/分轨][518.87MB]"><span>群星《奔赴!万人现场 第2期》[FLAC/分轨][518.8</span></a> </li> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/619122.html" one-link-mark="yes" title="群星《奇妙浪一夏 (上海迪士尼度假区音乐)》[320K/MP3][43.91MB]"><span>群星《奇妙浪一夏 (上海迪士尼度假区音乐)》[32</span></a> </li> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/619121.html" one-link-mark="yes" title="群星《奇妙浪一夏 (上海迪士尼度假区音乐)》[FLAC/分轨][140.49MB]"><span>群星《奇妙浪一夏 (上海迪士尼度假区音乐)》[FL</span></a> </li> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/619120.html" one-link-mark="yes" title="【古典音乐】詹姆斯·高威《季节》1993[WAV+CUE]"><span>【古典音乐】詹姆斯·高威《季节》1993[WAV+CUE]</span></a> </li> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/619119.html" one-link-mark="yes" title="贝拉芳蒂《卡里普索之王》SACD[WAV+CUE]"><span>贝拉芳蒂《卡里普索之王》SACD[WAV+CUE]</span></a> </li> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/619118.html" one-link-mark="yes" title="小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]"><span>小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]</span></a> </li> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/619117.html" one-link-mark="yes" title="群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]"><span>群星《欢迎来到我身边 电影原声专辑》[320K/MP3</span></a> </li> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/619116.html" one-link-mark="yes" title="群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]"><span>群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨</span></a> </li> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/619115.html" one-link-mark="yes" title="雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]"><span>雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓</span></a> </li> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/619114.html" one-link-mark="yes" title="群星《2024好听新歌42》AI调整音效【WAV分轨】"><span>群星《2024好听新歌42》AI调整音效【WAV分轨】</span></a> </li> </ul> </div> </div> <div class="sidebar"> </div> </article> <footer> <p style="font-size: 14px;">友情链接:<a href="http://www.imxmx.com/" title="杰晶网络" target="_blank">杰晶网络</a> <a href="http://www.ddrfans.com/" title="DDR爱好者之家" target="_blank">DDR爱好者之家</a> <a href="http://www.nqxw.com/" title="南强小屋" target="_blank">南强小屋</a> <a href="/" title="黑松山资源网" target="_blank">黑松山资源网</a> <a href="http://www.dyhadc.com/" title="白云城资源网" target="_blank">白云城资源网</a> <a href="/sitemap1.xml">站点地图</a> <a href="/sitemap.xml">SiteMap</a></p> <p>Design by <a href="http://m.paidiu.com">黑松山资源网</a> <a href="/">http://m.paidiu.com</a></p> </footer> <script src="/images/nav.js"></script> <script type="text/javascript"> jQuery.noConflict(); jQuery(function() { var elm = jQuery('#left_flow2'); var startPos = jQuery(elm).offset().top; jQuery.event.add(window, "scroll", function() { var p = jQuery(window).scrollTop(); jQuery(elm).css('position', ((p) > startPos) ? 'fixed' : ''); jQuery(elm).css('top', ((p) > startPos) ? '0' : ''); }); }); </script> </body> </html>