首先感谢您帮助我解决问题,Stackoverflow是一个很好的社区。同时请注意我对Javascript非常陌生。
这个问题涉及到我正在构建的网站:http://www.thewanderingguru.com/m2world2/?portfolio=the-trout 将浏览器宽度更改为小于960像素,以使移动菜单出现。现在点击页面右侧的菜单图标。您将看到主菜单栏出现,左侧的网站Logo会调整到页面下方。
我的问题是如何使Logo不会“跳”上下。我做了一些研究,并找到了我认为是用于缓和过渡效果的Jquery库,例如here,但我不确定如何在我的网站上实现它。请注意,此网站运行在Wordpress上。
我将包括管理菜单图标被点击时Logo类转换的代码。'.ubermenu-skin-vanilla.ubermenu-responsive-toggle'是菜单图标的类,当被点击时,将把“world”Logo(div id = '#logo')的类从“logo1”改为“logo2”。
我尝试添加CSS过渡效果,但没有帮助减轻#logo div的跳动。我认为需要JavaScript缓和效果,但我不知道如何实现它。再次感谢您的所有帮助和建议。
以下是Javascript代码:
这个问题涉及到我正在构建的网站:http://www.thewanderingguru.com/m2world2/?portfolio=the-trout 将浏览器宽度更改为小于960像素,以使移动菜单出现。现在点击页面右侧的菜单图标。您将看到主菜单栏出现,左侧的网站Logo会调整到页面下方。
我的问题是如何使Logo不会“跳”上下。我做了一些研究,并找到了我认为是用于缓和过渡效果的Jquery库,例如here,但我不确定如何在我的网站上实现它。请注意,此网站运行在Wordpress上。
我将包括管理菜单图标被点击时Logo类转换的代码。'.ubermenu-skin-vanilla.ubermenu-responsive-toggle'是菜单图标的类,当被点击时,将把“world”Logo(div id = '#logo')的类从“logo1”改为“logo2”。
我尝试添加CSS过渡效果,但没有帮助减轻#logo div的跳动。我认为需要JavaScript缓和效果,但我不知道如何实现它。再次感谢您的所有帮助和建议。
以下是Javascript代码:
<script type="text/javascript">jQuery(document).ready(function($) {$('.ubermenu-skin-vanilla.ubermenu-responsive-toggle').click(function(){$('#logo').toggleClass('logo1');$('#logo').toggleClass('logo2');});});</script>
这是我当前的CSS:
@media only screen and (min-width: 0px) and (max-width:959px){
.logo1{
margin-top: 20px !Important;
max-width: 90px !Important;
transition: margin-top,max-width .7s ease-in-out !Important;
-webkit-transition: margin-top,max-width .7s ease-in-out !Important;
-o-transition: margin-top,max-width .7s ease-in-out !Important;
-moz-transition: margin-top,max-width .7s ease-in-out !Important;
}
.logo2{
margin-top: 20px !Important;
max-width: 90px !Important;
transition: margin-top,max-width .7s ease-in-out !Important;
-webkit-transition: margin-top,max-width .7s ease-in-out !Important;
-o-transition: margin-top,max-width .7s ease-in-out !Important;
-moz-transition: margin-top,max-width .7s ease-in-out !Important;
}
.logo2{
margin-top: 170px !Important;
max-width: 90px !Important;
transition: margin-top,max-width .7s ease-in-out !Important;
-webkit-transition: margin-top,max-width .7s ease-in-out !Important;
-o-transition: margin-top,max-width .7s ease-in-out !Important;
-moz-transition: margin-top,max-width .7s ease-in-out !Important;
}
}
PS. 我知道在我的CSS中使用大量的“!Important”并不是最佳实践,但我使用的主题除非这样做,否则会覆盖我的代码。谢谢!