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>

图片效果

点击图片后变化

相关推荐
朴shu37 分钟前
Luckysheet 远程搜索下拉 控件开发 : 揭秘二开全流程
前端
MediaTea2 小时前
Python:模块 __dict__ 详解
开发语言·前端·数据库·python
字节跳动开源2 小时前
Midscene v1.0 发布 - 视觉驱动,UI 自动化体验跃迁
前端·人工智能·客户端
光影少年2 小时前
三维前端需要会哪些东西
前端·webgl
王林不想说话3 小时前
React自定义Hooks
前端·react.js·typescript
heyCHEEMS3 小时前
Uni-app 性能天坑:为什么 v-if 删不掉 DOM 节点
前端
马致良3 小时前
三年前写的一个代码工具,至今已被 AI Coding 完全取代。
前端·ai编程
橙某人3 小时前
LogicFlow 交互新体验:让锚点"活"起来,鼠标跟随动效实战!🧲
前端·javascript·vue.js
借个火er3 小时前
依赖注入系统
前端
借个火er3 小时前
项目介绍与环境搭建
前端