html--图片变化

目标效果:

1.图片为渐变

2.点击上传图片会有变化

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Document</title>

<meta charset="UTF-8">

<title>Document</title>

<style>

body {

background: linear-gradient(to right, red, blue);

transition: background 2s;

}

.colorful {

filter: hue-rotate(90deg);

}

</style>

</head>

<body>

<body>

<img id="myImage" src="your_image.jpg" alt="Your Image">

</body>

</body>

</html>

<script>

document.body.addEventListener('click', function () {

let currentDirection = getComputedStyle(this).backgroundImage.match(/to\s+(\w+)/)[1];

let newDirection = currentDirection === 'right' ? 'left' : 'right';

this.style.backgroundImage = `linear-gradient(to ${newDirection}, red, blue)`;

});

</script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<script>

$(document).ready(function () {

$('#myImage').click(function () {

$(this).toggleClass('colorful');

});

});

</script>

图片效果

点击图片后变化

相关推荐
码事漫谈2 小时前
大模型输出的“隐性结构塌缩”问题及对策
前端·后端
这儿有一堆花2 小时前
前端三件套真的落后了吗?揭开现代 Web 开发的底层逻辑
前端·javascript·css·html5
.Cnn3 小时前
JavaScript 前端基础笔记(网页交互核心)
前端·javascript·笔记·交互
醉酒的李白、3 小时前
Vue3 组件通信本质:Props 下发,Emits 回传
前端·javascript·vue.js
anOnion3 小时前
构建无障碍组件之Window Splitter Pattern
前端·html·交互设计
NotFound4863 小时前
实战分享Python爬虫,如何实现高效解析 Web of Science 文献数据并导出 CSV
前端·爬虫·python
徐小夕4 小时前
PDF无限制预览!Jit-Viewer V1.5.0开源文档预览神器正式发布
前端·vue.js·github
WangJunXiang64 小时前
Haproxy搭建Web群集
前端
阿部多瑞 ABU4 小时前
《智能学号抽取系统》V5.9.5 发布:精简代码,修复移动端文件读取核心 Bug
vue·html·bug
吴声子夜歌4 小时前
Vue.js——自定义指令
前端·vue.js·flutter