search
HomeWeb Front-endJS TutorialBootstrap implements pop-up and drag effects_javascript skills

Sometimes I feel quite comfortable developing some special effects. I can operate your webpage like my own computer. Here I will introduce a little multi-window and dragging effect using bootstrap!

Here, we do not use the static opening method, low..., 1. Add a link to trigger and open the button; 2. Write a dynamic opening js script; 3. Write modal intermediate content; 4. Add dragging Effect; 5. Open multiple modals and call dragModal(new Array('modalId1','modalId2'));

1. Add a link to trigger and open the button:

<a href="javascript:;" title="开关" class="open-modal-dynamic" url="index.php&#63;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. Write dynamic opening js script:

//打开弹窗
  $('.open-modal-dynamic').on('click', function(){
    var modalId = $(this).attr('divid') &#63; $(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. Write modal intermediate content:

<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&#63;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. Add drag effect:

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. Open multiple modals and call dragModal(new Array('modalId1','modalId2'));

The whole process is like this, please refer to it if necessary!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
JavaScript's Role: Making the Web Interactive and DynamicJavaScript's Role: Making the Web Interactive and DynamicApr 24, 2025 am 12:12 AM

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C   and JavaScript: The Connection ExplainedC and JavaScript: The Connection ExplainedApr 23, 2025 am 12:07 AM

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

From Websites to Apps: The Diverse Applications of JavaScriptFrom Websites to Apps: The Diverse Applications of JavaScriptApr 22, 2025 am 12:02 AM

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python vs. JavaScript: Use Cases and Applications ComparedPython vs. JavaScript: Use Cases and Applications ComparedApr 21, 2025 am 12:01 AM

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

The Role of C/C   in JavaScript Interpreters and CompilersThe Role of C/C in JavaScript Interpreters and CompilersApr 20, 2025 am 12:01 AM

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript in Action: Real-World Examples and ProjectsJavaScript in Action: Real-World Examples and ProjectsApr 19, 2025 am 12:13 AM

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

JavaScript and the Web: Core Functionality and Use CasesJavaScript and the Web: Core Functionality and Use CasesApr 18, 2025 am 12:19 AM

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding the JavaScript Engine: Implementation DetailsUnderstanding the JavaScript Engine: Implementation DetailsApr 17, 2025 am 12:05 AM

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment