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>

图片效果

点击图片后变化

相关推荐
Swift社区7 分钟前
从 0 到 1 构建一个完整的 AGUI 前端项目的流程在 ESP32 上运行
前端·算法·职场和发展
一只小风华~27 分钟前
学习笔记:Vue Router 中的链接匹配机制与样式控制
前端·javascript·vue.js·笔记·学习·ecmascript
Jerry_Rod37 分钟前
react+umijs 项目快速学习
前端·react.js
京东云开发者42 分钟前
浅析cef在win和mac上的适配
前端
uhakadotcom1 小时前
在chrome浏览器插件之中,options.html和options.js常用来做什么事情
前端·javascript·面试
西瓜树枝1 小时前
Chrome 扩展开发从入门到实践:以 Cookie 跨页提取工具为例,拆解核心模块与交互逻辑
前端·javascript·chrome
gplitems1231 小时前
Download:Blaxcut - Barbershop & Hair Salon WordPress Theme
前端
拜无忧1 小时前
【DEMO】互动信息墙 - 无限流动版-点击放大
前端
AliPaPa1 小时前
你可能忽略了useSyncExternalStore + useOptimistic + useTransition
前端·react.js