jquery实现点击侧边栏伸缩效果。点击收缩,侧边栏向左收缩,显示按钮显示;点击显示按钮,显示按钮向左收缩,侧边栏显示。

具体代码如下:

*{margin: 0;padding: 0;}

#box{width: 100%;height: 100%;}

#left{width: 200px;float: left;background-color: royalblue;position: relative;}

#btn{width: 100%;height: 50px;background-color: darkgoldenrod;line-height: 50px;text-align: center;color: white;cursor: pointer;}

#btnb{width: 50px;height: 50px;background-color: red;position: absolute;cursor: pointer;left: -50px;line-height: 50px;text-align: center;}

收缩

显示

$(function(){

$a = $(window).height();

$("#left").height($a);

$("#btn").click(function(){

$("#left").animate({left:'-200px'});

$("#btnb").delay(500).animate({left:'0'});

});

$("#btnb").click(function(){

$("#btnb").animate({left:'-50px'});

$("#left").delay(500).animate({left:'0'});

});

});

效果图:

5963803f5c7cfcdcbe53607cf7648fc9.png

以上这篇jquery实现侧边栏左右伸缩效果的示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐