兩張圖片對比clip功能

在這里插入圖片描述

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>圖片拖動Clip對比功能</title><style>* {margin: 0;padding: 0;box-sizing: border-box;}body {font-family: Arial, sans-serif;background-color: #f0f0f0;display: flex;justify-content: center;align-items: center;min-height: 100vh;padding: 20px;}.container {max-width: 800px;width: 100%;height: 500px;border-radius: 12px;overflow: hidden;background-color: white;box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);border: 1px solid #e0e0e0;}.image-comparison {position: relative;height: 100%;width: 100%;display: flex;overflow: hidden;touch-action: none;user-select: none;}.image-comparison img {display: block;width: 100%;height: 100%;object-fit: cover;object-position: center center;}.clip-item {position: absolute;top: 0;left: 0;width: 100%;height: 100%;user-select: none;will-change: clip-path;clip-path: inset(0 0 0 50%);transition: clip-path 0.1s ease-out;}.handle-container {position: absolute;top: 0;height: 100%;background: none;border: 0;padding: 0;pointer-events: all;appearance: none;outline: 0;transform: translate3d(-50%, 0, 0);left: 50%;cursor: ew-resize;z-index: 10;}.handle-root {display: flex;flex-direction: column;place-items: center;height: 100%;cursor: ew-resize;pointer-events: none;color: white;}.handle-line {flex-grow: 1;height: 100%;width: 2px;background-color: currentColor;pointer-events: auto;box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);}.handle-button {display: grid;grid-auto-flow: column;gap: 8px;place-content: center;flex-shrink: 0;width: 56px;height: 56px;border-radius: 50%;border: 2px solid currentColor;pointer-events: auto;backdrop-filter: blur(7px);background-color: rgba(0, 0, 0, 0.125);box-shadow: 0 0 4px rgba(0, 0, 0, 0.35);}.handle-arrow {width: 0;height: 0;border-top: 8px solid transparent;border-right: 10px solid currentColor;border-bottom: 8px solid transparent;}.handle-arrow:last-child {transform: rotate(180deg);}.info {position: absolute;bottom: 20px;left: 20px;background: rgba(0, 0, 0, 0.7);color: white;padding: 10px 15px;border-radius: 8px;font-size: 14px;z-index: 5;}@media (max-width: 768px) {.container {height: 400px;}.handle-button {width: 48px;height: 48px;}}</style>
</head>
<body><div class="container"><div class="image-comparison" id="imageComparison"><img alt="Original Image" src="./img/demo5.png"><div class="clip-item" id="clipItem"><img alt="Translated Image" src="./img/demo6.png"></div><button class="handle-container" id="handleContainer" aria-label="拖動移動或聚焦并使用箭頭鍵" aria-orientation="horizontal" aria-valuemin="0" aria-valuemax="100" aria-valuenow="50" role="slider"><div class="handle-root"><div class="handle-line"></div><div class="handle-button"><div class="handle-arrow"></div><div class="handle-arrow"></div></div><div class="handle-line"></div></div></button><div class="info">拖動中間的滑塊來對比兩張圖片</div></div></div><script>class ImageComparison {constructor(container) {this.container = container;this.clipItem = container.querySelector('#clipItem');this.handleContainer = container.querySelector('#handleContainer');this.isDragging = false;this.currentPosition = 50; // 初始位置 50%this.init();}init() {this.bindEvents();this.updatePosition(this.currentPosition);}bindEvents() {// 鼠標事件this.handleContainer.addEventListener('mousedown', this.handleMouseDown.bind(this));document.addEventListener('mousemove', this.handleMouseMove.bind(this));document.addEventListener('mouseup', this.handleMouseUp.bind(this));// 觸摸事件this.handleContainer.addEventListener('touchstart', this.handleTouchStart.bind(this));document.addEventListener('touchmove', this.handleTouchMove.bind(this));document.addEventListener('touchend', this.handleTouchEnd.bind(this));// 鍵盤事件this.handleContainer.addEventListener('keydown', this.handleKeyDown.bind(this));// 防止拖動時選中文本this.container.addEventListener('selectstart', (e) => e.preventDefault());}handleMouseDown(e) {e.preventDefault();this.isDragging = true;this.container.style.cursor = 'ew-resize';this.clipItem.style.transition = 'none';}handleMouseMove(e) {if (!this.isDragging) return;e.preventDefault();const rect = this.container.getBoundingClientRect();const x = e.clientX - rect.left;const percentage = (x / rect.width) * 100;this.updatePosition(Math.max(0, Math.min(100, percentage)));}handleMouseUp() {this.isDragging = false;this.container.style.cursor = '';this.clipItem.style.transition = 'clip-path 0.1s ease-out';}handleTouchStart(e) {e.preventDefault();this.isDragging = true;this.clipItem.style.transition = 'none';}handleTouchMove(e) {if (!this.isDragging) return;e.preventDefault();const touch = e.touches[0];const rect = this.container.getBoundingClientRect();const x = touch.clientX - rect.left;const percentage = (x / rect.width) * 100;this.updatePosition(Math.max(0, Math.min(100, percentage)));}handleTouchEnd() {this.isDragging = false;this.clipItem.style.transition = 'clip-path 0.1s ease-out';}handleKeyDown(e) {const step = 5;switch(e.key) {case 'ArrowLeft':e.preventDefault();this.updatePosition(Math.max(0, this.currentPosition - step));break;case 'ArrowRight':e.preventDefault();this.updatePosition(Math.min(100, this.currentPosition + step));break;case 'Home':e.preventDefault();this.updatePosition(0);break;case 'End':e.preventDefault();this.updatePosition(100);break;}}updatePosition(percentage) {this.currentPosition = percentage;// 更新clip-paththis.clipItem.style.clipPath = `inset(0 0 0 ${percentage}%)`;// 更新滑塊位置this.handleContainer.style.left = `${percentage}%`;// 更新ARIA屬性this.handleContainer.setAttribute('aria-valuenow', Math.round(percentage));}}// 初始化document.addEventListener('DOMContentLoaded', () => {const container = document.getElementById('imageComparison');new ImageComparison(container);});</script>
</body>
</html>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/914382.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/914382.shtml
英文地址,請注明出處:http://en.pswp.cn/news/914382.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

7.11 dp 圖

lcr148.棧按放入順序推棧&#xff0c;能彈出的就及時彈出&#xff0c;最后棧空則符合要求。判斷 takeOut 序列是否符合棧的操作邏輯&#xff0c;因為題目中“特殊的數據結構”其實就是棧&#xff08;先進后出&#xff09;。思路如下&#xff1a;1. 用一個棧來模擬圖書放入的過程…

react16-react19都更新哪些內容?

React 16 到 React 19 是 React 發展非常關鍵的階段&#xff0c;每個版本都帶來了深遠影響。以下是 React 16 → 19 的重要更新列表&#xff0c;按版本詳細說明每一代的核心特性、重要變化、對開發者的意義&#xff0c;并附簡評&#xff1a;? React 16&#xff08;2017 年&…

【AI大模型】RAG系統組件:向量數據庫(ChromaDB)

RAG 系統中的關鍵組件&#xff1a;向量數據庫&#xff08;Vector Database&#xff09;&#xff0c;并以 ChromaDB 為例進行說明。什么是向量數據庫&#xff1f;核心概念&#xff1a; 向量數據庫是一種專門設計用于高效存儲、索引和檢索高維向量的數據庫。向量是什么&#xff1…

006_測試評估與安全實踐

測試評估與安全實踐 目錄 建立成功標準評估方法測試策略安全最佳實踐隱私保護性能監控 建立成功標準 定義原則 1. 具體明確 清晰定義精確目標避免模糊表述如"良好性能"制定可操作的標準 不好的標準&#xff1a; 模型應該表現良好好的標準&#xff1a; 情感分…

時序預測 | Pytorch實現CNN-KAN電力負荷時間序列預測模型

預測效果 代碼功能 該代碼實現了一個結合卷積神經網絡&#xff08;CNN&#xff09;和Kolmogorov–Arnold網絡&#xff08;KAN&#xff09;的混合模型&#xff08;CNN-KAN&#xff09;&#xff0c;用于時間序列預測任務。核心功能包括&#xff1a; 數據加載與預處理&#xff1…

UI前端與數字孿生結合實踐探索:智慧物流的倉儲優化與管理系統

hello寶子們...我們是艾斯視覺擅長ui設計和前端數字孿生、大數據、三維建模、三維動畫10年經驗!希望我的分享能幫助到您!如需幫助可以評論關注私信我們一起探討!致敬感謝感恩!一、引言&#xff1a;倉儲管理的 “數字孿生革命”傳統物流倉儲正面臨 “效率瓶頸、可視化差、響應滯…

【Android】在平板上實現Rs485的數據通訊

前言 在工業控制領域&#xff0c;Android 設備通過 RS485 接口與 PLC&#xff08;可編程邏輯控制器&#xff09;通信是一種常見的技術方案。最近在實現一個項目需要和plc使用485進行通訊&#xff0c;記錄下實現的方式。 我這邊使用的從平的Android平板&#xff0c;從平里面已經…

MySQL技術筆記-備份與恢復完全指南

目錄 前言 一、備份概述 &#xff08;一&#xff09;備份方式 &#xff08;二&#xff09;備份策略 二、物理備份及恢復 &#xff08;一&#xff09;備份操作 &#xff08;二&#xff09;恢復操作 三、邏輯備份及恢復 &#xff08;一&#xff09;邏輯備份 &#xff0…

SpringBoot或OpenFeign中 Jackson 配置參數名蛇形、小駝峰、大駝峰、自定義命名

SpringBoot或OpenFeign中 Jackson 配置參數名蛇形、小駝峰、大駝峰、自定義命名 前言 在調用外部接口時&#xff0c;對方給出的接口文檔中&#xff0c;入參參數名一會大寫加下劃線&#xff0c;一會又是駝峰命名。 示例如下&#xff1a; {"MOF_DIV_CODE": "xx…

uni-app 途徑站點組件開發與實現分享

在移動應用開發中&#xff0c;涉及到出行、物流等場景時&#xff0c;途徑站點的展示是一個常見的需求。本文將為大家分享一個基于 uni-app 開發的途徑站點組件&#xff0c;該組件能夠清晰展示路線中的各個站點信息&#xff0c;包括站點名稱、到達時間、是否已到達等狀態&#x…

kotlin中集合的用法

從一個實際應用看起以下kotlin中代碼語法正確嗎 var testBeanAIP0200()var testList:List<AIP0200> ArrayList()testList.add(testBean)這段Kotlin代碼存在語法錯誤&#xff0c;主要問題在于&#xff1a;List<AIP0200> 是Kotlin中的不可變集合接口&#xff0c;不能…

深入理解 Java Map 與 Set

文章目錄前言1. 搜索樹1.1 什么是搜索樹1.2 查找1.3 插入1.4 刪除情況一&#xff1a;cur 沒有子節點&#xff08;即為葉子節點&#xff09;情況二&#xff1a;cur 只有一個子節點&#xff08;只有左子樹或右子樹&#xff09;情況三&#xff1a;cur 有兩個子節點&#xff08;左右…

excel如何只保留前幾行

方法一&#xff1a;手動刪除多余行 選中你想保留的最后一行的下一行&#xff08;比如你只保留前10行&#xff0c;那選第11行&#xff09;。按住 Shift Ctrl ↓&#xff08;Windows&#xff09;或 Shift Command ↓&#xff08;Mac&#xff09;&#xff0c;選中從第11行到最…

實時連接,精準監控:風丘科技數據遠程顯示方案提升試驗車隊管理效率

風丘科技推出的數據遠程實時顯示方案更好地滿足了客戶對于試驗車隊遠程實時監控的需求&#xff0c;并真正實現了試驗車隊的遠程管理。隨著新的數據記錄儀軟件IPEmotion RT和相應的跨平臺顯示解決方案的引入&#xff0c;讓我們的客戶端不僅可在線訪問記錄器系統狀態&#xff0c;…

灰盒級SOA測試工具Parasoft SOAtest重新定義端到端測試

還在為脆弱的測試環境、強外部依賴和低效的測試復用拖慢交付而頭疼&#xff1f;尤其在銀行、醫療、制造等關鍵領域&#xff0c;傳統的端到端測試常因環境不穩、接口難模擬、用例難共享而舉步維艱。 灰盒級SOA測試工具Parasoft SOAtest以可視化編排簡化復雜測試流程&#xff0c…

OKHttp 核心知識點詳解

OKHttp 核心知識點詳解 一、基本概念與架構 1. OKHttp 簡介 類型&#xff1a;高效的HTTP客戶端特點&#xff1a; 支持HTTP/2和SPDY&#xff08;多路復用&#xff09;連接池減少請求延遲透明的GZIP壓縮響應緩存自動恢復網絡故障2. 核心組件組件功能OkHttpClient客戶端入口&#…

從“被動巡檢”到“主動預警”:塔能物聯運維平臺重構路燈管理模式

從以往的‘被動巡檢’轉變至如今的‘主動預警’&#xff0c;塔能物聯運維平臺對路燈管理模式展開了重新構建。城市路燈屬于極為重要的市政基礎設施范疇&#xff0c;它的實際運行狀態和市民出行安全以及城市形象有著直接且緊密的關聯。不過呢&#xff0c;傳統的路燈管理模式當下…

10. 常見的 http 狀態碼有哪些

總結 1xx: 正在處理2xx: 成功3xx: 重定向&#xff0c;302 重定向&#xff0c;304 協商緩存4xx: 客戶端錯誤&#xff0c;401 未登錄&#xff0c;403 沒權限&#xff0c;404 資源不存在5xx: 服務器錯誤常見的 HTTP 狀態碼詳解 HTTP 狀態碼&#xff08;HTTP Status Code&#xff0…

springBoot對接第三方系統

yml文件 yun:ip: port: username: password: controller package com.ruoyi.web.controller.materials;import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.materials.service.IYunService; import o…

【PTA數據結構 | C語言版】車廂重排

本專欄持續輸出數據結構題目集&#xff0c;歡迎訂閱。 文章目錄題目代碼題目 一列掛有 n 節車廂&#xff08;編號從 1 到 n&#xff09;的貨運列車途徑 n 個車站&#xff0c;計劃在行車途中將各節車廂停放在不同的車站。假設 n 個車站的編號從 1 到 n&#xff0c;貨運列車按照…