利用JQuery动画制作滑动菜单项效果实现步骤及代码

2019-12-24,,,

效果:






点击第二个菜单项后出现一个向上滑动的动画,控制margin-top底部另一个div中的文字


上移从而替换掉原有的文字。






原理其实不难无非就是css的控制加之jquery的代码


对docemnt中所有li绑定一个hover事件,事件中根据鼠标的状态(无非是移入与移除),


使用animate的动画方式使原有的div向上移70px,移出时再将页面效果变回原有的样子。


代码如下:
复制代码 代码如下:
$(function () {
var webNav = {
val: {
target: 0
},

init: function () {
$(".gnb ul li").on("hover", webNav.hover);

},

hover: function (e) {
if ($(this).index() == webNav.val.target) { return };
if (e.type == "mouseenter") {
$(this).find("a>p").stop(true, true).animate({ "margin-top": "-70px" }, 300);
} else if (e.type == "mouseleave") {
$(this).find("a>p").stop(true, true).animate({ "margin-top": "0px" }, 300);
}
}
};
webNav.init();


});

您可能感兴趣的文章:

  • jQuery实现可用于博客的动态滑动菜单完整实例
  • jquery实现仿Flash的横向滑动菜单效果代码
  • jquery实现最简单的滑动菜单效果代码
  • jQuery实现带延迟效果的滑动菜单代码
  • jquery实现左右滑动菜单效果代码
  • jQuery实现可用于博客的动态滑动菜单
  • jQuery实现背景滑动菜单

《利用JQuery动画制作滑动菜单项效果实现步骤及代码.doc》

下载本文的Word格式文档,以方便收藏与打印。