跟着pink老师学JS的第三天总结

news2024/10/5 23:20:19

在这里插入图片描述
*

这个仿京东的商品放大镜效果真不好做!

鼠标拖拽:
*
在这里插入图片描述
代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .preview_img{
        position: relative;
        height: 398px;
        width: 398px;
        border:1px solid #ccc;
        box-shadow: 0 0 6px 5px rgba(0, 0, 0, 0.5);
    }
    .preview_img .small{
        width: 398px;
        height: 398px;
    }
    .mask{
        display: none;

        position: absolute;
        top:0; left:0;
        width: 300px; height: 300px;
        background-color: #FEDE4F;
        opacity: .4;
        border:1px solid #ccc;
        cursor: move;
    }
    .big{
        display: none;
        position: absolute;
        left:410px;
        top:0;
        width: 500px;
        height: 500px;
        background-color: pink;
        z-index:999 ;
        border:1px solid black;
        overflow: hidden;
    }
   .big .bigimg{
        position: absolute;
        top:0; left:0;
    }
</style>
<body>
    <div class="preview_img">
        <img src="img/b3.png" alt="" class="small">
        <div class="mask"></div>
        <div class="big">
            <img src="img/big.jpg" alt="" class="bigimg">
        </div>
    </div>
    
</body>
<script>
    var img=document.querySelector('.preview_img');
    var big=document.querySelector('.big');
    var mask=document.querySelector('.mask');
    img.addEventListener('mouseover',function(e) {
        big.style.display = "block";
        mask.style.display = "block";
     
    })
    img.addEventListener('mouseout',function(e) {
        big.style.display = "none";
        mask.style.display = "none";
     
    })
    img.addEventListener('mousemove',function(e) {
       var x=e.pageX-this.offsetLeft;
       var y = e.pageY - this.offsetTop;
       var maskX=x-mask.offsetWidth/2;
       var maskY=y-mask.offsetHeight / 2;
       var maskMax=  img.offsetWidth-mask.offsetWidth;
       if (maskX<0){
        maskX = 0;
       }
       if (maskY < 0) {
        maskY = 0;
       }
       if(maskX>maskMax){
        maskX=maskMax;
       }
    //    正方形宽高一样,所以maskMax可以替换
       if(maskY>maskMax){
        maskY=maskMax;
       }
     mask.style.left=maskX+'px';
     mask.style.top=maskY+'px';
//大图的移动距离:遮挡层移动距离*大图片最大移动距离 /遮挡层的最大移动距离

var bigImg=document.querySelector('.bigimg')
// 大图片最大移动距离
var bigMax=bigImg.offsetWidth-big.offsetWidth ;
    var bigX=(maskX)*bigMax/(maskMax);
   var bigY=(maskY)*bigMax/(maskMax);
   bigImg.style.left =-bigX + "px";
   bigImg.style.top = -bigY + "px";
   })
</script>
</html>

在这里插入图片描述

拖动模态框:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>

 .login-header {
            width: 100%;
            text-align: center;
            height: 30px;
            font-size: 24px;
            line-height: 30px;
        }
        
        ul,
        li,
        ol,
        dl,
        dt,
        dd,
        div,
        p,
        span,
        h1,
        h2,
        h3,
        h4,
        h5,
        h6,
        a {
            padding: 0px;
            margin: 0px;
        }
        
        .login {
            display: none;
            width: 512px;
            height: 280px;
            position: fixed;
            border: #ebebeb solid 1px;
            left: 50%;
            top: 50%;
            background: #ffffff;
            box-shadow: 0px 0px 20px #ddd;
            z-index: 9999;
            transform: translate(-50%, -50%);
        }
        
        .login-title {
            width: 100%;
            margin: 10px 0px 0px 0px;
            text-align: center;
            line-height: 40px;
            height: 40px;
            font-size: 18px;
            position: relative;
            cursor: move;
        }
        
        .login-input-content {
            margin-top: 20px;
        }
        
        .login-button {
            width: 50%;
            margin: 30px auto 0px auto;
            line-height: 40px;
            font-size: 14px;
            border: #ebebeb 1px solid;
            text-align: center;
        }
        
        .login-bg {
            display: none;
            width: 100%;
            height: 100%;
            position: fixed;
            top: 0px;
            left: 0px;
            background: rgba(0, 0, 0, .3);
        }
        
        a {
            text-decoration: none;
            color: #000000;
        }
        
        .login-button a {
            display: block;
        }
        
        .login-input input.list-input {
            float: left;
            line-height: 35px;
            height: 35px;
            width: 350px;
            border: #ebebeb 1px solid;
            text-indent: 5px;
        }
        
        .login-input {
            overflow: hidden;
            margin: 0px 0px 20px 0px;
        }
        
        .login-input label {
            float: left;
            width: 90px;
            padding-right: 10px;
            text-align: right;
            line-height: 35px;
            height: 35px;
            font-size: 14px;
        }
        
        .login-title span {
            position: absolute;
            font-size: 12px;
            right: -20px;
            top: -30px;
            background: #ffffff;
            border: #ebebeb solid 1px;
            width: 40px;
            height: 40px;
            border-radius: 20px;
        }
    </style>
</head>

<body>
    <div class="login-header"><a id="link" href="javascript:;">点击,弹出登录框</a></div>
    <div id="login" class="login">
        <div id="title" class="login-title">登录会员
            <span><a id="closeBtn" href="javascript:void(0);" class="close-login">关闭</a></span>
        </div>
        <div class="login-input-content">
            <div class="login-input">
                <label>用户名:</label>
                <input type="text" placeholder="请输入用户名" name="info[username]" id="username" class="list-input">
            </div>
            <div class="login-input">
                <label>登录密码:</label>
                <input type="password" placeholder="请输入登录密码" name="info[password]" id="password" class="list-input">
            </div>
        </div>
        <div id="loginBtn" class="login-button"><a href="javascript:void(0);" id="login-button-submit">登录会员</a></div>
    </div>
    <!-- 遮盖层 -->
    <div id="bg" class="login-bg"></div>
</body>
<script>
    var login=document.querySelector('.login');
    var mask = document.querySelector('.login-bg');
    var link=document.querySelector('#link');
    var closeBtn=document.querySelector('#closeBtn');
    //点击link,让mask和login显示出来
    link.addEventListener('click',function(e) {
        mask.style.display = "block";
        login.style.display = "block";
    })
    //点击closeBtn,就隐藏 mask和login
    closeBtn.addEventListener('click',function(e) {
        mask.style.display = "none";
        login.style.display = "none";
    })
//实现拖拽效果,在title位置才能进行拖拽
var title=document.querySelector("#title");
title.addEventListener("mousedown", function(e) {
    //获取鼠标的位置:e.pageX
  var y=e.pageY-login.offsetTop;
    var x=e.pageX-login.offsetLeft;
    //鼠标按下之后进行拖动
    //让鼠标在页面中的坐标减去鼠标在盒子里的坐标就是盒子的left和top值
    document.addEventListener('mousemove',move)
    function move(e) {
        login.style.left = e.pageX-x+'px';
        login.style.top = e.pageY - y + "px";
    }
    // 鼠标弹起,停止拖拽,移除事件
    document.addEventListener('mouseup',function(e) {
        document.removeEventListener('mousemove',move)
    })

})
</script>
</html>

在这里插入图片描述

倒计时效果:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    div{
        margin: 200px 400px;
    }
  
    h1{
        display: block;
        height: 60px;
        line-height: 10px;
        float: left;
    }
span{
    float: left;
    margin-right: 5px;
    display: block;
    width: 60px; height: 60px;
    background-color: black;
    color:aliceblue;
    font-size :20px;
    text-align: center;
    line-height: 60px;

}
p{
    float: left;
 
        height: 60px;
        line-height: 30px;

    width: 60px; height: 60px;
    color:black;
    font-size :30px;


}
</style>
<body>
    <div>
        <h1>倒计时:</h1>
        <span class="hour"></span><p></p>
        <span class="minute"></span><p></p>
        <span class="second"></span><p></p>
    </div>
</body>
<script>
    var hour=document.querySelector('.hour');
    var minute=document.querySelector('.minute');
    var second=document.querySelector('.second');
    
    var inputTime= +new Date("2022-12-30 10:50:00");  //返回的是用户输入时间总的毫秒数
   //先调用一次,防止刷新出现空白
   countDown();
    //开启定时器
    setInterval(countDown,1000)
    function countDown(time) {
        
        
        // 使用时间戳去计算不会出现负值
       var nowTime= +new Date(); //返回的是当前时间总的毫秒数
        
        var times=(inputTime - nowTime)/1000;  //times是剩余时间总的秒数

        var h=parseInt(times / 60 / 60 % 24);//小时
        h=h<10?'0'+h:h;
        hour.innerHTML=h;
       var m=parseInt(times / 60 % 60); //分钟
       m=m<10?'0'+m:m;
       minute.innerHTML = m;
       var s=parseInt(times % 60);//秒
       s=s<10?'0'+s:s;
        second.innerHTML = s;
        
   }

   

</script>
</html>

在这里插入图片描述

快递单号查询:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
            margin: 0;
            padding: 0;
        }
        
        .search {
            position: relative;
            width: 178px;
            margin: 100px;
        }
        
        .con {
            display: none;
            position: absolute;
            top: -40px;
            width: 171px;
            border: 1px solid rgba(0, 0, 0, .2);
            box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
            padding: 5px 0;
            font-size: 18px;
            line-height: 20px;
            color: #333;
        }
.con::before{
    content:"";
    width: 0; height: 0;
    position: absolute;
    top: 28px;
    left: 18px;
    border:8px solid #000;
    border-style:solid dashed dashed;
    border-color: aliceblue transparent transparent;

}
</style>
<body>
    <div class="search">
        <div class="con">123</div>
    <input type="text" placeholder="请输入快递单号" class="jd">
</div>
</body>
<script>
    var con=document.querySelector(".con");
    var jd=document.querySelector(".jd");
    jd.addEventListener('keyup',function(e){
       if(jd.value===''){
        con.style.display = "none";
       }else {con.style.display = "block";
       con.innerHTML=jd.value;}
    });
    //失去焦点,隐藏盒子
    jd.addEventListener('blur',function(e) {
        con.style.display = "none";
    });
    //获得焦点,显示盒子
    jd.addEventListener('focus',function(e) {
        if(jd.value !== "")
        con.style.display = "block";
    })
</script>
</html>

鼠标跟随:

黑马pink:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    img{
        position: absolute;
    }
</style>
<body>
    <!-- 按照绝对定位,获取鼠标位置,让"小天使”的位置随着鼠标变化,达成跟随效果 -->
<img src="angel.gif" alt="">
</body>
<script>
    var img=document.querySelector("img");
    document.addEventListener('mousemove',function(e){
       var x=e.pageX; 
       var y=e.pageY; 
        img.style.left=x-42+'px'
        img.style.top=y-34+'px'

    });
</script>
</html>

千峰:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{padding:0;  margin:0;}
        
        #box{
            width: 200px;
w            height: 50px;
            background-color: red;
            position: relative;
            margin: 100px;
        }
        #box p{
            width: 300px;
            height: 200px;
            background-color: aqua;
            position: absolute;
            left: 100px; top: 100px;
            display: none;
            pointer-events: none;
            /* 穿透 */
            z-index: 100;
        }
        </style>
</head>
<!-- 做一个点击头像然后显示内容 -->
<body>
    <div id="box">
        你的头像
        <p>
            头像介绍
        </p>
    </div>
</body>
<script>
 
box.onmouseover = function(){
    this.firstElementChild.style.display="block";
}
box.onmouseout = function(){
    this.firstElementChild.style.display="none";
}
box.onmousemove=function(evt){
    // console.log(evt.offsetX,evt.offsetY)
    this.firstElementChild.style.left=evt.offsetX+50+"px";
    this.firstElementChild.style.top=evt.offsetY+50+"px";  
}

</script>
</html>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/126884.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

FineReport报表设计工具- 配置DB2外接数据库(1)

1. 概述 1.1 版本 报表服务器版本 功能变更 11.0 - 11.0.3 1&#xff09;首次配置外接数据库时&#xff0c;支持自行选择是否「迁移数据至要启用的数据库」 2&#xff09;迁移外接数据库的过程提示细化&#xff0c;方便用户了解迁移进度 1.2 功能简介 报表系统配置外接数…

Seata使用教程

文章目录一、Seata简介1.Seata 概念介绍2.分布式事务3.Seata核心组件4.Seata 工作流程5.Seata四大模式二、Seata实战教程1.下载资源2.配置Seata-Server3.增加相关表结构4.代码配置三、常见报错解决一、Seata简介 1.Seata 概念介绍 Seata 是一款阿里巴巴开源的分布式事务解决方…

eNSP 设备启动失败,错误代码:40 解决方案

eNSP 路由器启动失败&#xff0c;错误代码&#xff1a;40 解决方案 eNSP 路由器启动失败&#xff0c;错误代码&#xff1a;40 解决方案 文章目录eNSP 路由器启动失败&#xff0c;错误代码&#xff1a;40 解决方案一、出现错误代码&#xff1a;40二、解决方法1.确定相关的软件安…

《设计模式》外观模式

《设计模式》外观模式《设计模式》设计模式的基本原则 《设计模式》单例模式 《设计模式》工厂模式 《设计模式》原型模式 《设计模式》建造者模式 《设计模式》适配器模式 《设计模式》桥接模式 《设计模式》装饰者模式 《设计模式》组合模式 《设计模式》外观模式 定义&#…

免费刷题!初级软件测试面试题目和答案这个小程序很全

有没有软件测试面试题库小程序&#xff1f;相信这是很多准备找工作的新手测试人都想要知道的吧&#xff01; 今天&#xff0c;我就根据大家的需求&#xff0c;为大家整理了一些有关初级软件测试的面试题目以及一个可以免费刷题的题库&#xff0c;希望能帮助你们早日拿下心仪的…

UDS-10 Diagnostic and communication management functional unit

10 诊断与通信管理功能单元 来自&#xff1a;ISO 14229-1-2020.pdf 10.1概述 表22指定了诊断和通信管理功能单元。 注&#xff1a; DiagnosticSessionControl&#xff1a;客户端请求控制服务器的诊断会话。ECUReset&#xff1a;客户端强制服务器执行重置。SecurityAccess&am…

知识蒸馏原理

文章目录0.知识蒸馏&#xff08;模型压缩的一种方法&#xff09;1.蒸馏2.为什么要蒸馏3.知识的表示与迁移4.蒸馏温度T5.知识蒸馏过程6.知识蒸馏的应用场景7.知识蒸馏背后的机理8.为什么用soft targets 而不用 label smoothing?9.知识蒸馏的研究方向10.知识蒸馏代码库11.扩展阅…

回顾2022,展望2023,笔耕不辍,钟情翰墨

目录 回顾2022 博客概览 博客成就 获得测试领域优质创作者认证 获得博客专家认证 获得额外收入 创建第一个属于自己的个人社区 获得第一个实体奖牌【博客专家】 首次登榜梦想照进现实CSDN实体奖牌榜 首次参与社区新锐和社区先锋评选 开启了6个知识体系系列教程 个人…

2023春招面试:消息中间件面试题整理

RabbitMQ如何确保消息发送 &#xff1f; 消息接收&#xff1f; 开启生产者确认机制&#xff0c;确保生产者的消息能到达队列&#xff08;config机制保证消息正确到达交换机、return机制保证消息正确到达队列&#xff09;开启持久化功能&#xff0c;确保消息未消费前在队列中不会…

如何通过WindowsIIS部署网站

1.winR输入control 打开【控制面板】 2.选择程序 3.选择【启用或关闭Windows功能】 4.在【Windows功能】对话框中勾选【Internet Information Services】下的【FTP服务器】、【Web管理工具】和【万维网服务】中的所有选项&#xff0c;并点击【确定】 5.Windows功能会开始下载并…

Lambda表达式的来龙去脉,全在这篇文章里了

一. 前言部分 大家都知道Lambda表达式作为JAVA 8中提供的新特性之一&#xff0c;在现在的企业开发中已经非常的流行了。今天壹哥就通过一个具体的案例&#xff0c;来带大家一起详细地探究一下Lambda表达式是如何被提出来的&#xff0c;以及它的出现主要是用来解决什么问题的。…

乌班图(Ubuntu)单系统或者乌班图+Win双系统安装教程

单ubuntu系统安装 1、将ubuntu系统U盘插入电脑USB接口&#xff0c;建议优先插USB3.0蓝色(彩色)接口&#xff0c;这样可以保证安装过程中文件的读取速度&#xff0c;加快安装进程。 2、然后电脑关机状态下&#xff0c;开机。开机后快速按主机的快捷启动键&#xff1a; 3、在出现…

Qt编写雷达模拟仿真工具1-背景布局

一、前言 雷达模拟仿真工具&#xff0c;整体结构采用的QGraphicsView框架&#xff0c;背景布局采用的分层绘制&#xff0c;这样可以控制该需要重新绘制的重新绘制&#xff0c;不需要重新的绘制的就没必要再多余的浪费&#xff0c;这里定义了一个GraphicsBackGroundItem类继承自…

Spring框架(容器)--简介(实现原理、核心模块、组成部分)

spring框架&#xff08;容器&#xff09; spring简介 1、Spring的用途不仅限于服务器端的开发。从简单性、可测试性和松耦合的角度而言&#xff0c;任何Java应用都可以从Spring中受益。 2、Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架。 3、轻量——从大小…

Creo9.0 Windows 3D建模工具

前言 creo9.0正式版是一款非常优秀的3D建模设计软件。该软件界面美观&#xff0c;提供了CAD 技术、模制造绘图、多实体建模、多体设计、实时仿真、框架和焊缝设计等一系列强大的辅助设计功能&#xff0c;通过这些功能&#xff0c;让用户轻松解决设计中带来的各种问题。 下载 …

律所管理系统的功能以及作用分别有哪些?

在全球进入信息化的时代&#xff0c;随着网络的普及与发展&#xff0c;网络所带来的信息交流与利用的优势愈发明显。尤其是随着法律制度的不断健全和人民法律意识的提高&#xff0c;涉及法律诉讼的案件也在不断地增加&#xff0c;律师事务所作为中介的法律机构&#xff0c;要处…

字符设备驱动(一)

1.Linux设备分类 linux的文件种类&#xff1a; -&#xff1a;普通文件 文件内容文件名元信息&#xff08;文件的相关属性—组织在inode的一个结构体内&#xff09; d&#xff1a;目录文件 p&#xff1a;管道文件 s&#xff1a;本地socket文件 l&#xff1a;链接文件 软链接&am…

4 内部类实例

内部类 内部类的分类&#xff1a; 成员内部类方法内部类局部内部类匿名类静态内部类 1 成员内部类 是在一个类中声明的类&#xff0c;包含内部类的是外围类 成员内部类的访问权限&#xff1a; public可以在外围类的外部使用内部类创建对象private只能在外围类的内部使用内…

提升Mac使用性能的5大方法,都非常的好用哦~

是不是发现你的 Mac 越用运行速度会越慢&#xff1f;没错&#xff0c;任何电子设备&#xff0c;随着使用时间的增加&#xff0c;都会出现不如刚买时那么流畅的问题。Mac当然也不能例外&#xff0c;它的运行速度会随着使用时长的递增而有所下降&#xff0c;所以为 Mac 提速也是十…

CSS总结(网页布局:标准流 浮动 定位)

CSS 主要的功能是布局页面&#xff0c;增加标签的样式和部分交互效果。 资料来源&#xff1a;黑马 目录 元素显示 块级元素 行内元素 行内块元素 显示模式的转换 CSS三个特点 盒子模型 传统三种布局 标准流 浮动 结合浮动和标准流可以搭建出常见的网页布局: 清除…