该功能实现的是:分左、右两边布局,左边div默认展开,左边div中有一个元素,点击实现左边div隐藏,右边div挤压过来;再点击实现左边显示,右边挤过去。

一、HTML代码:

<div class="cont-container">
<!-- 左侧div -->
<div class="cont-wrap-left" id="contWrapLeft">
<a href="javascript:;" class="cont-wrap-switch" id="J_contWrapSwitch">
<span></span>
</a>
</div> <!-- 右侧div -->
<div class="cont-wrap">
</div>
</div>

二、CSS代码:

/* 整个div样式 */
.cont-container {
position: relative;
overflow: hidden;
} /* 左侧div样式 */
.cont-wrap-left {
position: absolute;
top:;
left:;
width: 249px;
height: 100%;
border-right: 1px solid #E6E6E6;
z-index:;
} .cont-wrap-switch {
display: block;
position: absolute;
top:;
right:;
width: 18px;
height: 35px;
line-height: 35px;
border-left: 1px solid #E6E6E6;
background: #E6E9ED;
z-index:;
} .cont-wrap-switch sapn {
display: inline-block;
width: 18px;
height: 24px;
vertical-align: middle;
background: url(../images/switch_btn.png) no-repeat -1px -24px;
} .cont-wrap-switch:hover {
background: #DEE0E4;
} .cont-wrap-switch:hover sapn {
background: -1px -0;
} .cont-wrap-switch.off {
right: -18px;
background: #232C48;
} .cont-wrap-switch.off span {
background: url(../images/switch_btn.png) no-repeat -1px -72px;
} .cont-wrap-switch.off:hover {
background: #1F2740;
} .cont-wrap-switch.off:hover sapn {
background-position: -1px -48px;
}

三、JS代码:

<script type="text/javascript">
$("#J_contWrapSwitch").click(function(){
if($(this).hasClass("off")) {
$("#contWrapLeft").animate({ left: "0"});
$(".cont-wrap").animate({marginLeft: "250px"}, 300);
$(this).removeClass("off");
} else {
$("#contWrapLeft").animate({ left: "-255px"});
$(".cont-wrap").animate({marginLeft: "0"}, 300);
$(this).addClass("off");
}
});
</script>

jQuery实现点击控制左右两边元素挤压显示效果的更多相关文章

  1. js或jquery实现点击某个按钮或元素显示div,点击页面其他任何地方隐藏div

    点击某个元素显示div,点击页面其他任何地方隐藏div,可用javascript和jquery两种方法实现: 一:javascript实现方法技巧<script>//定义stopPropa ...

  2. jquery实现点击控制div的显示和隐藏

    我们使用点击显示.点击隐藏的时候,一般有两种可选方案 .示例 html <div class="index"> <h1> 首页 </h1> &l ...

  3. jquery插件——点击交换元素位置(带动画效果)

    一.需求的诞生 在我们的网页或者web应用中,想要对列表中的元素进行位置调整(或者说排序)是一个常见的需求.实现方式大概就以下两种,一种是带有类似“上移”.“下移”的按钮,点击可与相邻元素交换位置,另 ...

  4. 微信小程序点击控制元素的显示与隐藏

    微信小程序点击控制元素的显示与隐藏 首先我们先来看一下单个点击效果 我们来看一下wxml中的代码: <view class="conten"> <view cla ...

  5. Jquery的点击事件,三句代码完成全选事件

    先来看一下Js和Jquery的点击事件 举两个简单的例子 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&q ...

  6. JQuery实现点击按钮切换图片(附源码)--JQuery基础

    JQuery实现切换图片相对比较简单,直接贴代码了哈,有注释噢!疑问请追加评论哈,不足之处还请大佬们指出! 1.案例代码: demo.html: <!DOCTYPE html><ht ...

  7. jquery 实现点击图片居住放大缩小

    该功能是基于jquery实现的,所以 第一步则是引入jquery jquery下载地址:https://jquery.com/download/ 或者使用此时调试的版本(3版本) /*! jQuery ...

  8. 用js或JQuery模拟点击a标签的操作

    一.用js模拟点击a标签的操作. jsp代码: <a id="login" href="${pageContext.request.contextPath}/log ...

  9. JQuery 当点击input后,单选多选的选中状态

    1.当点击input元素,此元素的选中checked的值 = 此元素此时表现的选中与否的状态. eg:input元素开始是未选中,点击后表现的是选中状态,此元素的checked为true(和此元素开始 ...

随机推荐

  1. tensorflow object detection

    Follow guidelin from https://github.com/tensorflow/models/blob/master/research/object_detection/g3do ...

  2. nexus 私有 maven 仓库的搭建

    下载地址 页面 : https://help.sonatype.com/repomanager3/download 首先需要安装jdk .安装棒法我 前面的文章有写.https://www.cnblo ...

  3. 弱网测试—Network-Emulator-Toolkit工具

    参考别人网址:http://blog.csdn.net/no1mwb/article/details/53638681 弱网测试,属于健壮性测试:怎么样去做弱网测试呢? 一.安装弱网测试工具-Netw ...

  4. js 控件样式显隐和赋值

    控制样式显示: $("#againMetting")[0].style.display = "inline";//显示 $("#againMettin ...

  5. chmod命令详解

    Linux chmod命令 Linux/Unix 的文件调用权限分为三级 : 文件拥有者.群组.其他.利用 chmod 可以藉以控制文件如何被他人所调用. 使用权限 : 所有使用者 语法: chmod ...

  6. 阅读<All Digital VCXO Replacement for Gigabit Transceiver Applications>笔记(2)---XAPP589

    阅读<All Digital VCXO Replacement for Gigabit Transceiver Applications>笔记(2)---XAPP589 1. 2. 3. ...

  7. linux lftp

    1.登录 lftp 用户名@站点 口令: 例如: lftp jiangzhaowei@192.168.199.73 口令:****** lftp jiangzhaowei@192.168.199.73 ...

  8. 黄聪:C#“多线程线程间操作无效: 从不是创建控件的线程访问它。”,跨线程修改控件属性解决方案

    解决方案就是使用代理,在代理中调用主线程的方法来控制控件 /// <summary> /// 声明代理 /// </summary> delegate void SetText ...

  9. Visual Studio 2019/2017 安装使用教程(快速上手版)

    目录 Visual Studio 2017 安装使用教程(详细) 在此鸣谢范华对本文工作的大力支持 一.下载 二.安装 2017版本新建项目过程 2019版本新建项目过程 然后你就可以简单编写一段代码 ...

  10. Linux bash笔记

    关于bash脚本,一般开头都加#!/bin/bash,表示以bash来作为脚本解释器:如果不加的话,就会默认当前用户登陆的shell为脚本解释器(很多情况下为sh,sh与bash不同,有可能导致脚本无 ...