JQUERY案例

news2024/9/23 15:29:22

电梯导航

<!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>
    <!-- 导入文件 -->
    <script src="index.js"></script>
    <script src="jQuery.min.js"></script>
</head>
<style>
    *{
        list-style: none;
        padding:0;
        margin:0;
    }
.w{
width: 500px;
/* height: 1000px; */
margin:0 auto;
background: #fff;
}
h3{
    font-size: 30px;
    text-align: center;
    line-height: 200px;
}
.floor{
    margin-bottom:100px;
}
.floor img{
    width: 500px;
    height: 700px;
    margin:0 auto;
}
.dianti{
    display: none;
    /* 不能随着页面滚动而上升,采取fixed定位 */
    position: fixed;
    top: 300px;
    left: 100px;
    height: 200px;
    width: 100px;
    background-color: #fff;

}
.dianti ul li:first-child{
border-top:1px solid black ;

}
.dianti ul li{
font-size: 14px;
overflow: hidden;
line-height: 64px;
text-align: center;
color: black;
border-bottom:1px solid black ;

cursor: pointer;
}

/* 再加一个类,提高优先级,不然字体和颜色都不会生效 */
.dianti .current{
    color: #fff;
    background-color: #c81623;
    font-weight: 700;
}
#recom{
   
    margin:0 auto;
width: 500px;
height: 200px;
background-color: #c81623;
}
.footer{
    width: 500px;
    height: 400px;
    background-color: #c81623;
}
.footer h3{
    
    font-size: 30px;
    text-align: center;
    line-height: 400px;
}
.tuijian{
   
    margin:0 auto;
    background-color: aqua;
    width: 500px;
    height: 300px;
}
</style>
<body>
    <div class="tuijian"></div>
    <div  id="recom"><h3>电梯导航的使用</h3></div>
    
    <div class="w">
        <div class="floor ">
            <div class="w img1"  >
                <img src="img/水蜜桃.jpg" alt="">
            </div>
        </div>
        <div class="floor">
            <div class="w img2">
                <img src="img/水蜜桃2.jpg" alt="">

            </div>
        </div>
        <div class="floor">
            <div class="w img3">
                <img src="img/水蜜桃3.jpg" alt="">

            </div>
        </div>
         <div class="floor">
            <div class="w img4">
                <img src="img/水蜜桃4.jpg" alt="">

            </div>
        </div> 
        <div class="floor">
            <div class="w img5">
                <img src="img/水蜜桃5.jpg" alt="">

            </div> 
        </div>
        <div class="footer">
            <h3>底部</h3>
        </div>
    </div>
    <!-- 电梯导航 -->
<div class="dianti">
    <ul>
       
        <li class="current">图片一</li>
        <li>图片二</li>
        <li>图片三</li>
        <li>图片四</li>
        <li>图片五</li>

       
    </ul>
</div>
</body>
<script>
    $(function() {
    //点击li,此时不需要执行页面滚动事件里面的li的背景选择添加current
    //节流阀 互斥锁
    var flag=true;
    //到达一定位置,自动出现
    var toolTop=$("#recom").offset().top;
    toggleTool();
    function toggleTool(){
        if($(document).scrollTop()>=toolTop){
            $(".dianti").fadeIn();
        }else {
            $(".dianti").fadeOut();
        
        }
    }
   $(window).scroll(function(){
    toggleTool();
    // 页面滚动到响应区域,电梯导航也随之变化
    if(flag===true){
        $(".floor .w").each(function(i,ele) {
            if($(document).scrollTop()>=$(ele).offset().top){
                $(".dianti li").eq(i).addClass("current").siblings().removeClass("current")
            }
    
        })
    }
});
// 点击电梯导航页面可以滚动到对应区域
$(".dianti li").click(function() {
    flag=false;
//     index() 方法返回指定元素相对于其他指定元素的 index 位置。
// 这些元素可通过 jQuery 选择器或 DOM 元素来指定
    console.log($(this).index());
    //每次点击li,就需要计算页面要去往的位置
   var current= $(".floor .w").eq($(this).index()).offset().top;
//页面动画滚动效果
$("body,html").stop().animate({
    scrollTop : current,
},function() {
    flag=true;
});
$(this).addClass("current").siblings().removeClass("current")
})


})
</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;
    }
    body{
        height: 2000px;
    }
    .top{
        margin: 0 auto;
        width: 700px;
        height: 600px;
        background-color: khaki;

    }
    .back{
        margin: 0 auto;
        width: 700px;
        height: 600px;
        background-color: pink;
       
    }
    .container{
        position: absolute;
        top:800px;
        right: 50px;
        width: 80px;
        height: 80px;
        background-color: rebeccapurple;
        font-size:30px;
        overflow: hidden;
        text-align: center;
        display: none;
    }
</style>
<body>
    <div class="top">顶部</div>
    <div class="back">中间</div>
    <div class="container">
返回顶部
    </div>
</body>
<script src="jQuery.min.js"></script>
<script>
$(function() {
    //直接赋值,刷新直接跳到指定位置
    // $(document).scrollTop(100);
    var boxTop=$(".back").offset().top;
    $(window).scroll(function() {
        // console.log("你好")
        $(document).scrollTop();
        console.log($(document).scrollTop());
        if($(document).scrollTop()>=boxTop){
            // $(".container").css("display","block");
            // $(".container").show();
            $(".container").fadeIn()
        }else {
            $(".container").fadeOut()

        }
    })
// 返回顶部功能
$(".container").click(function() {
    //不带有动画
    // $(document).scrollTop(0);
    // 动画必须是页面元素在进行操作【document不行】:
    $("body,html").stop().animate({
        scrollTop:0
    },700)

})
})
</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>
        div{
            width: 200px;
            height: 200px;
            background-color: pink;
            padding:10px;
            border:15px solid red;
            margin:20px;
        }
    </style>
</head>
<body>
    <div></div>
</body>
<script src="jQuery.min.js"></script>
<script>
    $(function() {
        // 改变宽度
        // $("div").width(300);
        // $("div").css("width",400);

        // width:只测出原始盒子大小,不包括边框
        console.log($("div").width());
        // innerWidth:包含内边距
      console.log($("div").innerWidth());
    //   包含内边距和边框
    console.log($("div").outerWidth());
     //包含内外边距以及边框
     console.log($("div").outerWidth(true));
    })
   
</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>
        
      
    </style>
</head>

<body>
    <div class="father" > <input type="checkbox" checked>
    <span class="price">¥12.80</span><button class="de">-</button><input type="text" value="1" class="tex"><button class="in">+</button> <span class="price1">¥12.80</span><button class="del">删除</button>
    <!-- <span class="price">¥12.80</span><button class="de">-</button><input type="text"value="1" class="tex"><button class="in">+</button> <span class="price1">¥12.80</span><br>
    <span class="price">¥12.80</span><button class="de">-</button><input type="text"value="1" class="tex"><button class="in">+</button> <span class="price1">¥12.80</span> -->
    <div class="choose">已选择&nbsp;<span>1</span>&nbsp;件商品</div>
    <div class="sum">总价:<span>¥12.80</span>&nbsp;</div>
</div>
</body>
<script src="jQuery.min.js"></script>
<script>
// 文本框里面的值获取使用val(),普通元素里面的值获取使用text()
$(".in").click(function() {
    var n=$(this).siblings(".tex").val();
    // console.log(n);
    n++;
    $(this).siblings(".tex").val(n);
    var price =$(this).siblings(".price").html();
    // console.log(price)
    //截取字符串
    p=price.substr(1);
// console.log(p)
$(this).siblings(".price1").html('¥'+(p*n).toFixed(2));
getSum()
})

$(".de").click(function() {
    var n=$(this).siblings(".tex").val();
    // console.log(n);
    if (n == 0) {
        return false;
    }
    n--;
    $(this).siblings(".tex").val(n);
    var price =$(this).siblings(".price").html();
    // console.log(price)
    //截取字符串
    p=price.substr(1);
// console.log(p)
$(this).siblings(".price1").html('¥'+(p*n).toFixed(2));
getSum()
})
// 用户直接修改文本框的值  不过需要离开焦点后才能触发
$(".tex").change(function() {
   var n= $(this).val();
    var price =$(this).siblings(".price").html();
    p=price.substr(1);
$(this).siblings(".price1").html('¥'+(p*n).toFixed(2));
getSum()
})
//封装一个函数,用于计算总计和总额
getSum();
function getSum(){
    var count=0;
    var money=0;
    $('.tex').each(function(i,ele) {
        count+=parseInt($(ele).val());
    });  
    $(".choose").children("span").text(count);
    $(".price1").each(function(i, ele) {
        money += parseFloat($(ele).text().substr(1));
    });
    $(".sum").children("span").text('¥'+money.toFixed(2));
}
$(".del").click(function() {
    $(this).parents(".father").remove();
})
// 选中添加背景颜色
// if($("input").prop("checked")){
//     $(".father").addClass("bc");
// }
// else {
//     $(".father").removeClass("bc");
// }
</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>
        
      
    </style>
</head>

<body>
    <div class="father" > <input type="checkbox" checked>
    <span class="price">¥12.80</span><button class="de">-</button><input type="text" value="1" class="tex"><button class="in">+</button> <span class="price1">¥12.80</span><button class="del">删除</button>
    <!-- <span class="price">¥12.80</span><button class="de">-</button><input type="text"value="1" class="tex"><button class="in">+</button> <span class="price1">¥12.80</span><br>
    <span class="price">¥12.80</span><button class="de">-</button><input type="text"value="1" class="tex"><button class="in">+</button> <span class="price1">¥12.80</span> -->
    <div class="choose">已选择&nbsp;<span>1</span>&nbsp;件商品</div>
    <div class="sum">总价:<span>¥12.80</span>&nbsp;</div>
</div>
</body>
<script src="jQuery.min.js"></script>
<script>
// 文本框里面的值获取使用val(),普通元素里面的值获取使用text()
$(".in").click(function() {
    var n=$(this).siblings(".tex").val();
    // console.log(n);
    n++;
    $(this).siblings(".tex").val(n);
    var price =$(this).siblings(".price").html();
    // console.log(price)
    //截取字符串
    p=price.substr(1);
// console.log(p)
$(this).siblings(".price1").html('¥'+(p*n).toFixed(2));
getSum()
})

$(".de").click(function() {
    var n=$(this).siblings(".tex").val();
    // console.log(n);
    if (n == 0) {
        return false;
    }
    n--;
    $(this).siblings(".tex").val(n);
    var price =$(this).siblings(".price").html();
    // console.log(price)
    //截取字符串
    p=price.substr(1);
// console.log(p)
$(this).siblings(".price1").html('¥'+(p*n).toFixed(2));
getSum()
})
// 用户直接修改文本框的值  不过需要离开焦点后才能触发
$(".tex").change(function() {
   var n= $(this).val();
    var price =$(this).siblings(".price").html();
    p=price.substr(1);
$(this).siblings(".price1").html('¥'+(p*n).toFixed(2));
getSum()
})
//封装一个函数,用于计算总计和总额
getSum();
function getSum(){
    var count=0;
    var money=0;
    $('.tex').each(function(i,ele) {
        count+=parseInt($(ele).val());
    });  
    $(".choose").children("span").text(count);
    $(".price1").each(function(i, ele) {
        money += parseFloat($(ele).text().substr(1));
    });
    $(".sum").children("span").text('¥'+money.toFixed(2));
}
$(".del").click(function() {
    $(this).parents(".father").remove();
})
// 选中添加背景颜色
// if($("input").prop("checked")){
//     $(".father").addClass("bc");
// }
// else {
//     $(".father").removeClass("bc");
// }
</script>
</html>

each操作

<!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>
<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
</body>
<script src="jQuery.min.js"></script>
<script >
    $(function() {
        var sum=0;
        var arr=["red","greed","yellow"]
        $("div").each(function(index,domEle) {
            // domEle是一个DOM对象,必须转化为jq对象才能进行操作
            console.log(index);
            $(domEle).css("color",arr[index]);
            sum+=parseFloat($(domEle).text());
          
        })
        console.log(sum)

        $.each(arr,function(i,ele){
            console.log(i);
            console.log(ele);
        })
    })
</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>
<body>
    <div class="one">
        <div class="two">
            <div class="three">
                <div class="four">孙子</div>
            </div>
        </div>
    </div>
</body>
<script src="jQuery.min.js"></script>
<script>
    console.log($(".four").parents(".one"));
</script>
</html>

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

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

相关文章

一、pyhon准备工作篇(黑马程序猿-python学习记录)

黑马程序猿的python学习视频&#xff1a;https://www.bilibili.com/video/BV1qW4y1a7fU/ 目录 1. python官网 2. 检查是否安装完毕 3. pycharm官网 5. phcharm更换主题 6. 新建第一个python文件 7. pycharm字体大小设置 ​​​​​​​8. 设置快捷键 设置字体大小 ​​​​​​…

AJAX 简介

AJAX 是一种在无需重新加载整个网页的情况下&#xff0c;能够更新部分网页的技术。 AJAX 是什么&#xff1f; AJAX Asynchronous JavaScript and XML. AJAX 是一种用于创建快速动态网页的技术。 AJAX 通过在后台与服务器进行少量数据交换&#xff0c;使网页实现异步更新。这…

第三章 关系数据库标准语言SQL

第三章 关系数据库标准语言SQL 目录第三章 关系数据库标准语言SQL3.1 SQL概述3.1.1 产生与发展3.1.2 SQL的特点3.1.3 SQL的基本概念3.2 数据库实例3.3 数据定义3.3.1 模式的定义和删除3.2.2基本表的定义、删除和修改1.常见数据类型2.定义基本表3.修改基本表4.删除基本表5.模式和…

2. 返回传播计算方法|神经网络整体架构|神经元个数对结果的影响|正则化与激活函数|神经网络过拟合解决方法

文章目录返回传播计算方法神经网络整体架构&#xff08;暂时留存&#xff0c;等后面补&#xff09;神经元个数对结果的影响正则化与激活函数神经网络过拟合解决方法返回传播计算方法 实际上计算L&#xff08;损失值&#xff09;的时候并不是只是拿一组w来进行计算&#xff0c;…

用过MyBatis-Plus,我再也不想用mybatis了——MyBatis-Plus快速入门加常见注解总结,一文快速掌握MyBatis-Plus

相比与mybatis只做增强&#xff0c;不做修改 MyBatis-Plus学习笔记一&#xff0c;是什么二&#xff0c;入门案例1.建库建表2.创建spring Boot工程3.配置相关包及类4.测试三&#xff0c;基本的curd1.BaseMapper2.通用Service四.常用注解1.TableName2.TableId3TableField4.TableL…

【python】面向对象编程

文章目录一、函数大全1.1 匿名函数 lambda1.2 过滤函数 filter1.3 format1.4 try和except1.5 位置参数和关键字参数二、类与对象2.1创建对象2.2 封装的实现方式2.3 继承2.4方法重写2.5 object 类2.5.1 __str()__2.5.2 dict()2.5.3 len()2.5.4 add()2.5.5 new()init()2.6 多态的…

初识C语言(下)

写在前面 好了,现在我们开始C语言的第二个部分.今天我们需要看下面几个知识点,都是非常简单的,我们主要认识一下. 数组 我们知道一个一个属性可以用一个类型去表示,那么我想问的是如果是一个属性的多个呢?也就是多个一样的东西,此时我们就要使用数组来进行表示,所谓的数组就…

22. 输入和输出

1. 输出格式美化 (1) 如果你希望输出的形式更加多样&#xff0c;可以使用 str.format() 函数来格式化输出值。 (2) 如果你希望将输出的值转成字符串&#xff0c;可以使用 repr() 或 str() 函数来实现。   str()&#xff1a; 函数返回一个用户易读的表达形式。   repr()&am…

产品原型设计方法

产品原型设计方法1. 色彩选择与按钮设计1.1色彩选择1.2 按钮设计2. 使用原型设计中的基础元素2.1 使用文字元素2.2 使用图标元素3. 设计导航菜单栏和卡片式布局3.1设计导航菜单栏4.3 设计卡片式布局4. 使用UI框架4.1 使用UI框架的好处4.2 常用的UI框架1. 色彩选择与按钮设计 1…

K8s:通过 kubectl 插件 Kubepug 实现集群升级检查(废弃API资源检查)

写在前面 分享一个小工具&#xff0c;可用于 版本升级的 废弃 API 对象检查博文内容涉及&#xff1a; kubepug 离线安装&#xff0c;配置 kubectl 插件kubepug 两种方式离线使用 Demo 理解不足小伙伴帮忙指正 昔我往矣&#xff0c;杨柳依依。今我来思&#xff0c;雨雪霏霏。 —…

【HBase入门】1. HBase基础

简介 Hadoop 从 1970 年开始&#xff0c;大多数的公司数据存储和维护使用的是关系型数据库大数据技术出现后&#xff0c;很多拥有海量数据的公司开始选择像Hadoop的方式来存储海量数据Hadoop使用分布式文件系统HDFS来存储海量数据&#xff0c;并使用 MapReduce 来处理。Hadoo…

【Ajax】同源策略、跨域和JSONP

一、同源策略什么是同源如果两个页面的协议&#xff0c;域名和端口都相同&#xff0c;则两个页面具有相同的源。例如&#xff0c;下表给出了相对于 http://www.test.com/index.html 页面的同源检测&#xff08;如果没有写端口号&#xff0c;默认是80&#xff09;&#xff1a;UR…

开篇点睛——Elasticsearch

在互联网当中我们的查询的信息主要包括文章、视频、图片、网站信息等各式各样的复杂海量信息。怎么才能快速、准确的检索到我们想要的信息呢? 传统意义上根据数据的格式&#xff0c;我们会将数据分为三个大类 结构化数据非结构化数据半结构化数据 接下来我们详细的了解一下这…

Day07 - 面向对象

1. 面向对象概述 面向对象是一种对现实世界理解和抽象的方法&#xff0c;是计算机编程技术发展到一定阶段后的产物。 面向对象是相对于面向过程来讲的&#xff0c; 面向对象方法 &#xff0c;把相关的数据和方法组织为一个整体来看待&#xff0c;从更高的层次来进行系统建模&a…

开发人员必备的 15 个备忘单

随着网络编程技术的快速发展&#xff0c;我们必须学习很多新东西。有些语言和框架非常复杂&#xff0c;您可能记不住所有的语法或方法。备忘单是易于访问的笔记。当有人在过去目睹任何有帮助或有价值的事情时&#xff0c;包括我自己&#xff0c;我们都会做笔记。但是&#xff0…

Vue 快速入门(四)

前面已经介绍Vue常用指令的基本应用&#xff0c;这篇介绍Vue的一些特殊属性的使用。 01 - 计算属性Computed 计算属性关键词&#xff1a;Computed。 计算属性在处理一些复杂逻辑时是很有用的。 普通的写法 比如字符串反转普通写法&#xff0c;如下&#xff1a; <!DOCTYPE h…

Godot根据遮罩图移动粒子

前言 目前UI粒子特效unity引擎比较多&#xff0c;也好找资料&#xff0c;但是一般都是利用模型&#xff0c;使用3D粒子伪装2D效果。 Godot中也可以做到这一点&#xff0c;并且Godot有专门的2D粒子系统&#xff0c;可以通过一张遮罩图对粒子的位置进行设置。 godot粒子教程 …

nginx学习笔记6(小d课堂)

高并发-服务端缓存前置 我们现在启动了我们的一个jar包。 这次我们的nginx配置文件只保留这个。 我们先更改了它的文件名称。 然后我们现在利用默认的先去复制一份nginx配置文件&#xff1a; 我们这样就初始化完了我们的nginx配置文件。 记得加上我们的分号。 然后我们再重启…

AcWing第87场周赛题解

抱歉&#xff0c;3题只有前2题&#xff0c;第三题投入产出比太低&#xff0c;就不做了 一&#xff0c;移动棋子 4797. 移动棋子 - AcWing题库 题目 难度&#xff1a;简单 思路 直接套dfs模板&#xff0c;起点通过输入时得到&#xff0c;终点&#xff08;3&#xff0c;3&am…

Multiple Dimension Input 处理多维特征的输入

文章目录6、Multiple Dimension Input 处理多维特征的输入6.1 Revision6.2 Diabetes Dataset 糖尿病数据集6.3 Logistic Regression Model 逻辑斯蒂回归模型6.4 Mini-Batch&#xff08;N samples&#xff09;6.5 Neural Network 神经网络6.6 Diabetes Prediction 糖尿病预测6.6…