用jquery实现  百度换肤的模式;

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>百度换肤</title>
<style>
*{
padding:0;
margin:0;
}
body{
/*width:100%;*/
background:url('../js/2.jpg') no-repeat center 0; /*设置了body的背景图片 然后居中显示 然后只显示一次 */
background-size:cover; /*自适应屏幕大小*/
}
.box{
width:100%;
padding-top: 40px;
background-color: rgb(255,0,0,0.3);
text-align: center;
}
.box img{
width:100px;
/*height:20px;*/
}
</style>
</head>
<body>
<div class="box">
<img src="../js/2.jpg" alt="" id="pic1" >
<img src="../js/1.jpg" alt="" id="pic2" >
<img src="../js/3.jpg" alt="" id="pic3">
<img src='../js/4.jpg' alt="" id="pic4">
<img src="../js/5.jpg" alt="" id="pic5">
</div> <script type="text/javascript" src="../jquery-3.3.1.js"></script>
<script type="text/javascript">
$(function(){
$('.box img').click(function(){ //先获取 你的body下的img
console.log($(this)); //打印这个你点击的图片
var imgUrl = $(this)[0]['src']; //因为你获取的this是一个对象 而且这个对象只有第一条数据是有效果的 所以你取到第一条数据中的图片的路径
console.log($(this)[0]['src']);
$('body').css('background',`url(${imgUrl})`); //把你点击的图片的路径给设置成body的背景图片 并且为了让它能识别出来就用字符串把它拼接起来
$(this).css('width',200).siblings().css('width',100);
})
})
</script>
</body>
</html>

百度换肤

最新文章

  1. ---ps 命令
  2. 测试Swift语言代码高亮-使用highlight.js
  3. c# BackGroundWorker 多线程操作的小例子
  4. iOS 的 Gif 渲染引擎 FLAnimatedImage-b
  5. 基于.NET MVC的高性能IOC插件化架构(二)之插件加载原理
  6. ASP.NET MVC WebApi 返回数据类型序列化控制(json)
  7. 8.23.1 IO-输入输出流概念
  8. git clone下载代码
  9. Linux命令行下编辑常用的快捷键
  10. JavaWeb开发流程
  11. CentOS6.8下MySQL MHA架构搭建笔记
  12. idea 快捷键ctrl+shift+f失效的解决方案
  13. linux 网络命令
  14. Android代码安全工具集
  15. poj 1703 - Find them, Catch them【带权并查集】
  16. 使用Spring的AbstractRoutingDataSource类来进行拓展多数据源
  17. Python2.7-getpass
  18. ASP.NET 5 RC 2:UrlRouting 设置(不包含MVC6的UrlRouting设置)
  19. Xcode: Show Bounds Rectangles for UIView in Interface Builder
  20. WPF 绑定StaticResource到控件的方法

热门文章

  1. PHP 中 strlen 获取中英 字符长度 以作以后对比使用
  2. javac之向前引用
  3. Android开源项目xUtils HttpUtils模块分析(转)
  4. 【Qt开发】QDate类
  5. PHP之string之rtrim()函数使用
  6. C#定义一个类,并生成属性的例子
  7. 基础语言知识C++
  8. 【转】Java面试题全集(上)
  9. 【译】Steve Yegge的文章《Practicing Programming》
  10. Docker学习(一): 基本概念