在web开发中,我们经常利用css和javascript库来增强用户界面的视觉效果和交互性。像wow.js这样的库能够实现滚动时触发的动画效果,结合animate.css等动画库,可以轻松创建动态的网页内容。然而,当我们将这些在在线开发环境(如codepen)中正常运行的代码迁移到本地ide或其他项目中时,常常会遇到“xxx is not defined”之类的错误,这通常是由于缺少必要的外部资源引用所致。本教程将详细阐述如何正确引入这些外部依赖,以确保您的动画在任何环境中都能顺利运行。
在Codepen这类在线平台上,许多常用的库可能已经默认引入,或者通过简单的配置即可使用。但在本地开发环境中,您需要手动引入所有外部CSS样式表和JavaScript脚本。当您看到类似WOW is not defined的错误时,这意味着浏览器无法找到WOW这个全局对象,因为它所依赖的WOW.js库文件尚未被加载。
为了使动画和相关功能正常工作,我们需要引入以下关键库:
所有外部资源通常通过CDN(内容分发网络)链接引入,这能够加快加载速度并减轻服务器负担。您需要在HTML文件的
标签内引入CSS文件,并在标签的底部(之前)引入JavaScript文件,以确保DOM元素在脚本执行前已加载。以下是实现给定动画所需的所有CDN链接:
立即学习“前端免费学习笔记(深入)”;
<!-- Google Fonts - Source Sans Pro --> <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700,900&" rel="stylesheet"/> <!-- Google Fonts - Open Sans --> <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700&subset=latin,latin-ext" rel="stylesheet"/> <!-- Font Awesome for icons --> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet"/> <!-- Animate.css for predefined animations --> <link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.6/animate.min.css" rel="stylesheet"/> <!-- jQuery library (must be loaded before WOW.js and your custom scripts) --> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <!-- WOW.js library --> <script src="https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.min.js"></script>
将上述CDN链接、您的自定义CSS样式以及JavaScript代码整合到一个完整的HTML文件中,即可确保动画正常工作。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Web动画集成教程</title> <!-- 外部CSS库引用 --> <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700,900&" rel="stylesheet"/> <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700&subset=latin,latin-ext" rel="stylesheet"/> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet"/> <link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.6/animate.min.css" rel="stylesheet"/> <!-- 自定义CSS样式 --> <style> body { font-family: Open Sans, "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif; font-size: 13px; color: #666; position: relative; -webkit-font-smoothing: antialiased; margin: 0; } * { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, p, blockquote, th, td { margin: 0; padding: 0; font-size: 13px; direction: ltr; } .sectionClass { padding: 80px 0px 50px 0px; position: relative; display: block; background: rgb(249, 249, 249); } .row { width: 980px; height: 100%; max-width: 100%; margin: 0 auto; } .row:before, .row:after { content: ""; display: table; } .sectiontitle { background-position: center; text-align: center; min-height: 20px; } .sectiontitle h2 { font-size: 30px; color: #222; margin-bottom: 0px; padding-right: 10px; padding-left: 10px; } .headerLine { width: 160px; height: 2px; display: inline-block; background: #101F2E; } .fullWidth { width: 100%; display: table; float: none; padding: 0; min-height: 1px; height: 100%; position: relative; } /********************************/ /* SECTION WORK EXPERIENCE ********************************/ #work-experience .sectiontitle .headerLine { width: 280px; } #work-experience .headerline { width: 280px; } .cbp_tmtimeline { margin: 60px 30px 0 0; padding: 0; list-style: none; position: relative; } .cbp_tmtimeline:before { content: ''; position: absolute; top: 3%; bottom: 0; width: 10px; background: #324454; left: 13%; height: 100%; } .cbp_tmtimeline li:last-child:before { content: initial; } .cbp_tmtimeline > li .cbp_tmtime { display: block; width: 25%; padding-right: 100px; position: absolute; } .cbp_tmtimeline > li .cbp_tmtime span { display: block; text-align: right; } .cbp_tmtimeline > li .cbp_tmtime span:first-child { font-size: 0.9em; color: #bdd0db; } .cbp_tmtimeline > li .cbp_tmtime span:last-child { font-size: 2.9em; color: #3594cb; } .cbp_tmtimeline > li:nth-child(odd) .cbp_tmtime span:last-child { color: #6cbfee; } .cbp_tmtimeline > li .cbp_tmlabel { margin: 0 0 15px 25%; background: rgba(50, 68, 84, 1); color: #FFF; padding: 30px; font-size: 1.2em; font-weight: 300; line-height: 1.4; font-family: 'Open Sans'; position: relative; border-radius: 5px; min-height: 150px; } .cbp_tmtimeline > li:nth-child(odd) .cbp_tmlabel { background: #2B3A48; } .cbp_tmtimeline > li .cbp_tmlabel h3 { margin-top: 0px; color: white; font-size: 20px; margin-bottom: 5px; padding: 0 0 10px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.4); font-family: 'Open Sans', sans-serif; font-weight: bold; } .cbp_tmtimeline > li .cbp_tmlabel h4 { opacity: 0.7; color: rgba(255, 255, 255, 1); letter-spacing: 0px; font-family: 'Source Sans Pro', sans-serif; font-size: 18px; line-height: 1.2em; font-weight: 600; padding: 0; padding-bottom: 10px; margin: 0; text-align: left; } .cbp_tmtimeline > li .cbp_tmlabel h4 i { margin-right: 5px; vertical-align: middle; } .cbp_tmtimeline > li .cbp_tmlabel:after { right: 100%; border: solid transparent; content: " "; height: 0; width: 0; position: absolute; pointer-events: none; border-right-color: rgba(50, 68, 84, 1); border-width: 10px; top: 70px; } .cbp_tmtimeline > li:nth-child(odd) .cbp_tmlabel:after { border-right-color: #2B3A48; } .cbp_tmtimeline > li .cbp_tmicon { width: 150px; height: 150px; top: 3%; speak: none; font-style: normal; font-weight: normal; font-variant: normal; text-transform: none; font-size: 1.4em; line-height: 40px; -webkit-font-smoothing: antialiased; position: absolute; color: #151515; background: #324454; border-radius: 50%; text-align: center; left: 8%; margin: 0 0 0 -25px; } .cbp_tmtimeline li { margin-bottom: 70px; position: relative; } .sectionClassProject { position: relative; display: block; /* background: #f7f7f7; */ margin: 0 auto; padding: 80px 1.875em 3.125em; } .projectParagraph { font-size: 18px; margin: 0.5em 0 0; font-family: 'Source Sans Pro', serif; } .projectParagraphLink { font-size: 15px !important; font-weight: 500 !important; margin-top: 50px !important; margin-bottom: 0px; text-align: right; } .projectParagraphLink a { color: white; text-decoration: underline; } .cbp_tmicon img { width: 100%; } .faPra { display: inline-block; font: normal normal normal 14px/1 FontAwesome; text-rendering: auto; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; font-size: 70px; vertical-align: middle; color: white; line-height: 150px; } .label { background-color: rgba(255, 255, 255, 0.3); border-radius: 3px; color: #FFFFFF; display: inline; font-size: 12px; font-weight: bold; margin-right: 10px; padding: 5px 15px; } .date { color: #BFC3C7; display: block; font-size: 14px; font-weight: 600; position: absolute; top: 30px; right: 20px; } .date i { margin-right: 8px; vertical-align: top; font-size: 18px; line-height: 20px; } @media (max-width: 1024px) { .cbp_tmtimeline:before { display: none; } .cbp_tmtimeline > li .cbp_tmtime { width: 100%; position: relative; padding: 0 0 20px 0; } .cbp_tmtimeline > li .cbp_tmtime span { text-align: left; } .cbp_tmtimeline > li .cbp_tmlabel { margin: 30px 0 70px 0; padding: 50px 30px 30px 30px; font-weight: 400; font-size: 95%; float: left; } .cbp_tmtimeline > li .cbp_tmlabel:after { right: auto; border-right-color: transparent; border-bottom-color: rgb(50, 68, 84); top: -20px; } .cbp_tmtimeline > li:nth-child(odd) .cbp_tmlabel:after { border-right-color: transparent; border-bottom-color: rgb(43, 58, 72); left: 65px; } .cbp_tmtimeline > li:nth-child(even) .cbp_tmlabel:after { right: 65px; } .cbp_tmtimeline > li:nth-child(odd) .cbp_tmicon { position: relative; float: left; left: auto; margin: 0px 5px 0 0px; } .cbp_tmtimeline > li:nth-child(even) .cbp_tmicon { position: relative; float: right; left: auto; margin: 0px 5px 0 0px; } .cbp_tmtimeline > li .cbp_tmtime span:last-child { font-size: 1.5em; } } @media (max-width: 32em) { .cbp-ntaccordion { font-size: 70%; } } /********************************/ /* AUTHOR LINK ********************************/ footer { z-index: 100; padding-top: 50px; padding-bottom: 50px; width: 100%; bottom: 0; left: 0; } footer p { color: rgba(255, 255, 255, 0.8); font-size: 16px; opacity: 0; font-family: 'Open Sans'; width: 100%; word-wrap: break-word; line-height: 25px; -webkit-transform: translateX(-200px); transform: translateX(-200px); margin: 0; } footer .authorWindow a { text-decoration: none; } footer p strong { color: rgba(255, 255, 255, 0.9); margin-left: 5px; cursor: pointer; } .about-me-img { width: 120px; height: 120px; left: 10px; /* bottom: 30px; */ position: relative; border-radius: 100px; border: 1px solid #4A5F67; } .about-me-img img { margin-top: 8px; margin-left: 5px; } .authorWindow { width: 600px; background: #101F2E; padding: 22px 20px 22px 20px; border-radius: 5px; overflow: hidden; } .authorWindowWrapper { display: none; left: 110px; bottom: -20px; padding-left: 30px; position: absolute; } .trans { opacity: 1; -webkit-transform: translateX(0px); transform: translateX(0px); transition: all 500ms ease; } @media screen and (max-width: 768px) { .authorWindow { width: 210px; } .authorWindowWrapper { bottom: -170px; margin-bottom: 20px; } footer p { font-size: 14px; } } </style> </head> <body> <!-- 页面内容 --> <div id="workexperience" class="sectionClass"> <div class="row "> <div class="sectiontitle"> <h2>Work experience</h2> <span class="headerLine"></span> </div> <div class="fullWidth eight columns"> <ul class="cbp_tmtimeline"> <li> <div class="cbp_tmicon cbp_tmicon-phone"> <i class="faPra fa-briefcase"></i> </div> <div class="cbp_tmlabel wow fadeInRight animated"> <h3>Web developer</h3> <div class="date"> <i class="fa fa-calendar"></i>April 2014 - Current </div> <h4><i class="fa fa-flag"></i>Davic Company, Bratislava</h4> <p class="projectParagraph">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugit obcaecati ipsa quae, iusto laudantium qui, nisi eum modi perspiciatis quasi facilis corporis iure soluta enim incidunt itaque aspernatur sequi tempora.</p> </div> </li> <li> <div class="cbp_tmicon cbp_tmicon-screen"> <i class="faPra fa-briefcase"></i> </div> <div class="cbp_tmlabel wow fadeInRight animated"> <h3>Web designer</h3> <h4><i class="fa fa-flag"></i>Fannous Company, Prague</h4> <div class="date"><i class="fa fa-calendar"></i>June 2012 - April 2014</div> <p class="projectParagraph">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Deserunt quasi perspiciatis, aliquid sed maiores accusamus. Adipisci quidem nostrum quos quae doloremque esse a, ipsum earum, recusandae omnis dignissimos et sint.</p> </div> </li> <li> <div class="cbp_tmicon cbp_tmicon-mail"> <i class="faPra fa-briefcase"></i> </div> <div class="cbp_tmlabel wow fadeInRight animated"> <h3>Web designer</h3> <h4><i class="fa fa-flag"></i>Techixs Company, London</h4> <div class="date"><i class="fa fa-calendar"></i>November 2009 - June 2012</div> <p class="projectParagraph">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla labore atque alias ipsa, nam quod rerum repellat cumque, aliquam sequi vitae voluptatibus cum soluta incidunt tempore accusamus eius sed excepturi!Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempora natus veritatis aperiam repellendus dolor vel, expedita assumenda eos, mollitia quae ullam esse voluptas vero. Dolores culpa eaque vitae eum
以上就是在不同IDE中实现CSS/JS动画:WOW.js与其他库的集成的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 //m.sbmmt.com/ All Rights Reserved | php.cn | 湘ICP备2023035733号