bootstrap使用之多个弹窗和拖动效果[开发篇]
有时开发一些特效,自己感觉挺爽的,像操作自己电脑一样操作你的网页,这里就介绍一个使用bootstrap的一点多窗口和拖动效果吧!
这里,我们不使用静态打开的的方式,low...,1、添加一个a链接 触发,打开按钮;2、编写动态打开js脚本; 3、编写modal中间内容;4、添加拖动效果;5、打开多个modal , 调用dragModal(new Array('modalId1','modalId2'));
1、添加一个a链接 触发,打开按钮:
<a href="javascript:;" title="开关" class="open-modal-dynamic" url="index.php?m=index&c=cc&a=aa&id=22" alert='1' divid="editModal">打开modal<a>
<div id="addModal" class="modal hide fade" style="max-width:800px;" data-backdrop="static"></div> <!-- 打开容器 -->
2、编写动态打开js脚本:
//打开弹窗
$('.open-modal-dynamic').on('click', function(){
var modalId = $(this).attr('divid') ? $(this).attr('divid') : 'Modal', url = $(this).attr('url');
$.get(url, function(data){
if(data.status == 1){
//禁止选择文字,在拖动时会有影响
$('html').off('selectstart').on('selectstart', function(){return false;});
$('#' + modalId).html(data.htmlData);
$('#' + modalId).modal({'show':true});
}else{
alert(data.info);
}
}, 'json');
3、编写modal中间内容:
<style>
.line{margin-bottom: 5px;}
.line .left{width: 100px;text-align:right;display:block;}
.form-button{padding:2px 10px;background:#73A86A;color:#ffffff;border:none;}
.form-button:hover{background:#146206;}
</style>
<div class="modal-header">
<a class="close" title="关闭小窗口" data-dismiss="modal">×</a>
<h3>modal window<h3>
</div>
<div class="modal-body" style="padding-bottom: 5px;">
<div class="line">
<span class="left">脚本名称:</span>
<span>
<select name="name">
<option value='11'>11</option>
<option value='22'>22</option>
</select>
</span>
</div>
<div class="line">
<span class="left">日期:</span>
<span style="word-break:break-all;" title="的时间">
<input class="Wdate ipt date-picker" style="width: 100px;margin: 0;" type="text" id="date_add" value="" />
</span>
</div>
<div class="line" title="设置">
<span class="left">是否停止:</span>
<span>
<label><input type="radio" name="is_del_add" value="1" />强制停止</label>
<label><input type="radio" name="is_del_add" value="0" />正常处理</label>
</span>
</div>
<div class="line" title="按照实际情况允许进行模拟更改">
<span class="left">执行情况:</span>
<span>
<label><input type="radio" name="status_add" value="5" onclick="javascript:return confirm('你确定要操作该状态吗,这是系统的操作,请确认?');" />11</label>
<label><input type="radio" name="status_add" value="1" onclick="javascript:return confirm('你确定要操作该状态吗,这是系统的操作,请确认?');" />22成</label>
<label><input type="radio" onclick="javascript:return confirm('你确定要操作该状态吗,这是系统的操作,请确认?');" name="status_add" value="2"/>223行</label>
<label><input type="radio" onclick="javascript:return confirm('你确定要操作该状态吗,这是系统的操作,请确认?');" name="status_add" value="0" />445</label>
<label><input type="radio" onclick="javascript:return confirm('你确定要操作该状态吗,这是系统的操作,请确认?');" name="status_add" value="4" />55失败</label>
</span>
</div>
<div class="line">
<span>操作说明:</span>
<textarea name="memo" id="memo" cols="100" rows="1" style="width:370px;></textarea>
</div>
<div class="line" style="text-align:center;">
<input type="button" value="提交" class="form-button" id="submit2" />
<input type="hidden" id="id_add" value="22" />
</div>
</div>
<div class="modal-footer">
<span class="loading"></span>
<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
</div>
<script src="/js/dragModal.js"></script>
<script>
$(function(){
$('#submit2').off().on('click', function(){
var status = $('input[name=status_add]:checked').val(),
memo = $('#memo').val(),
id = parseInt($('#id_add').val()),
is_del = $('input[name=del_add]:checked').val(),
cron_name = $('#name_add').val(),
cron_date = $('#date_add').val(),
url ='index.php?m=xx&c=xx&a=';
if(!memo){
alert('请填写操作备注,如不处理,请直接关闭对话框!');
return false;
}
$.post(url, {status: status, cron_name:cron_name, memo: memo, id: id, cron_date: cron_date, is_del: is_del}, function(data){
if(data.status == 1){
alert(data.info);
window.location.reload();
}else{
alert(data.info);
}
}, 'json')
}); });
// drag effects begin, define the global variables to receive the changes,because of the different function of the modal
dragModal('editModal');
</script>
4、添加拖动效果:
var clicked = "0";
var dif = {};
;function dragModal(obj) { if(clicked == undefined || obj == undefined || dif == undefined){
return false;
}
if(typeof obj == 'string')
{
obj = new Array(obj);
}
var modalNums = obj.length;
//drag effects begin
var i = 0;
for (i = 0; i < modalNums; i++) {
dif[obj[i]] = {'difx': 0, 'dify': 0};
}
$("html").off('mousemove').on('mousemove', function (event) {
if (clicked == "0") {
for (i = 0; i < modalNums; i++) {
dif[obj[i]].difx = event.pageX - $("#" + obj[i]).offset().left;
dif[obj[i]].dify = event.pageY - $("#" + obj[i]).offset().top;
}
}
if (clicked > 0 && clicked <= modalNums) {
var clickedObj = obj[clicked - 1];
var newx = event.pageX - dif[clickedObj].difx - $("#" + clickedObj).css("marginLeft").replace('px', '');
var newy = event.pageY - dif[clickedObj].dify - $("#" + clickedObj).css("marginTop").replace('px', '');
$("#" + clickedObj).css({top: newy, left: newx});
} }); $("html").off('mouseup').on('mouseup', function (event) {
clicked = "0";
}); for(i = 0; i < modalNums; i++){
//注重此处不能直接传入i值,此处即为添加多窗口时的效果使用
$("#" + obj[i] + " .modal-header").off().on('mousedown',{index: i}, function (event) {
clicked = event.data.index + 1;
});
$("#" + obj[i] + " .modal-footer").off().on('mousedown', {index: i}, function (event) {
clicked = event.data.index + 1;
});
$('#' + obj[i]).on('hide.bs.modal', function () { //关闭时打开选中
$('html').off('selectstart').on('selectstart', function () {
return true;
});
}); }
}
5、打开多个modal , 调用dragModal(new Array('modalId1','modalId2'));
整个过程即是如此,有需要的,就参考参考吧!
bootstrap使用之多个弹窗和拖动效果[开发篇]的更多相关文章
- JS组件系列——基于Bootstrap Ace模板的菜单和Tab页效果分享(你值得拥有)
前言:最近园子里多了许多谈语言.谈环境.谈逼格(格局)的文章,看看笑笑过后,殊不知其实都是然并卵.提升自己的技术才是王道.之前博主分享过多篇bootstrap组件的文章,引起了很多园友的关注和支持,看 ...
- vc++ mfc中拖动效果的实现 借助于CImageList
拖动是界面编程频繁使用的一个效果,在windows系统下可谓大行其道.纵观时下的应用软件几乎各个都支持各种各样拖动的效果,windows7更是把拖动做到了极致.其实说起来拖动的实现也很简单,对于有句柄 ...
- js实现一个可以兼容PC端和移动端的div拖动效果
前段时间写了一个简单的div拖动效果,不料昨天项目上正好需要一个相差不多的需求,就正好用上了,但是在移动端的时候却碰到了问题,拖动时候用到的三个事件:mousedown.mousemove.mouse ...
- 使用jquery实现简单的拖动效果,分享源码
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkEAAAERCAIAAADzAOSQAAALRklEQVR4nO3dW5LaaAKEUfa/NkfMGu
- Bootstrap:弹出框和提示框效果以及代码展示
前言:对于Web开发人员,弹出框和提示框的使用肯定不会陌生,比如常见的表格新增和编辑功能,一般常见的主要有两种处理方式:行内编辑和弹出框编辑.在增加用户体验方面,弹出框和提示框起着重要的作用,如果你的 ...
- JS组件Bootstrap实现弹出框和提示框效果代码
这篇文章主要介绍了JS组件Bootstrap实现弹出框和提示框效果代码,对弹出框和提示框感兴趣的小伙伴们可以参考一下 前言:对于Web开发人员,弹出框和提示框的使用肯定不会陌生,比如常见的表格新增和编 ...
- GridView拖动效果实现
GridView拖动效果实现 1. 重新GridView控件 package com.whbs.drag.widget; import com.whbs.drag.DragGridActivit ...
- jquery div拖动效果示例代码
div拖动效果想必大家都有见到过吧,实现的方法也是有很多的,下面为大家将介绍使用jquery是如何实现的,感兴趣的朋友不要错过 复制代码代码如下: <%@ page language=" ...
- 使用jQuery实现简单的拖动效果
转自:http://www.muzilei.com/archives/136 如何实现拖动效果? 浏览DEMO 首先分析下拖动效果原理: 1.当鼠标在被拖动对象上按下鼠标(触发onmousedown事 ...
随机推荐
- (译)内存沉思:多个名称相关的神秘的SQL Server内存消耗者。
原文出处:https://blogs.msdn.microsoft.com/sqlmeditation/2013/01/01/memory-meditation-the-mysterious-sql- ...
- Java 集合类实现原理
转载自:http://blog.csdn.net/qq_25868207/article/details/55259978 :##ArrayList实现原理要点概括 参考文献:http://zhang ...
- React createRef:引用
一 代码 import React, { Component } from 'react'; class Box extends Component { render() { return <b ...
- 187. Repeated DNA Sequences重复的DNA子串序列
[抄题]: All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: &qu ...
- 使用安装脚本安装Texlive
介绍 TeX Live 是 TUG (TeX User Group) 维护和发布的 TeX 系统,可说是「官方」的 TeX 系统.网上可找到的教程大多是从镜像安装完整版texlive.镜像发布的周期较 ...
- [leetcode]254. Factor Combinations因式组合
Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a func ...
- Agile PLM 开发中AgileAPI类型对应控制台分类说明
1) 分类中的一级大类PLM后台管理的控制台中,每个分类中的一级大类都对应AgileAPI中一个类型 IServiceRequest对应产品服务请求,表为:psrIPrice对应价格,表为:pr ...
- springmvc mybatis shiro构建cms系统
开发语言: java.ios.android 部署平台: linux.window jdk版本:JDK1.7以上版本 开发工具: eclipse.idea等 服务器中间件:Tomcat 6.7.Jbo ...
- jdk8 永久代变更
java8 去掉了永久代permgen(又称非堆,其实也是堆的一部分),类的方法代码,常亮,方法名,静态变量等存放在永久代中 改为使用元空间 Metaspace , Metaspace 不在是堆的一部 ...
- Python12/11--盒子的显隐/布局/z-index/流式布局思想
1.盒子的显隐 display:none 在页面中不占位,采用定位布局后,显示隐藏都不会影响其他标签,不需要用动画处理时,一般用这个 opacoity : 0 在页面中占位,采 ...