javascript - Image Map wImage-Based Rollovers Bounded by AREA Coordinates, jQuery if Possible - Stack Overflow

Basically I need this:...but instead of just having the <AREA> tags recieve a border or fill colo

Basically I need this:

...but instead of just having the <AREA> tags recieve a border or fill color on rollover, have them recieve a background image. The image needs to be clipped by the shape of the <AREA>s.

Any ideas?

Basically the setup I have is as follows:

<img usemap="#map" />
<map name="map">
  <area coords="foo,bar">
  <area coords="foo,bar">
  <area coords="foo,bar">
</map>

And I want the background image of each AREA tag to change on rollover.

A faux version of what I want is here:

tankedup-imaging. /css_dev/rollover.html

...except that here, notice this is not a "true" image map, the rollover areas are not really bound by AREA tags.

Basically I need this:

http://plugins.jquery./project/maphilight

...but instead of just having the <AREA> tags recieve a border or fill color on rollover, have them recieve a background image. The image needs to be clipped by the shape of the <AREA>s.

Any ideas?

Basically the setup I have is as follows:

<img usemap="#map" />
<map name="map">
  <area coords="foo,bar">
  <area coords="foo,bar">
  <area coords="foo,bar">
</map>

And I want the background image of each AREA tag to change on rollover.

A faux version of what I want is here:

tankedup-imaging. /css_dev/rollover.html

...except that here, notice this is not a "true" image map, the rollover areas are not really bound by AREA tags.

Share Improve this question edited Sep 9, 2009 at 16:30 Dirk Diggler asked Sep 2, 2009 at 18:38 Dirk DigglerDirk Diggler 8651 gold badge11 silver badges23 bronze badges 1
  • I can't get the jQuery plugin page to load. Hopefully, what I put in my answer is close to what you are looking for. – Raleigh Buckner Commented Sep 2, 2009 at 21:53
Add a ment  | 

2 Answers 2

Reset to default 2

I don't think you can do this with a true image map:

<img usemap="#map" />
<map name="map">
    <area coords="foo,bar">
    <area coords="foo,bar">
    <area coords="foo,bar">
</map>

But, there is a way to do what you are wanting with only HTML and CSS using a variation of the CSS sprites technique. A tutorial of how to do it is here: http://www.noobcube./tutorials/html-css/css-image-maps-a-beginners-guide-/

A short overview of this technique: DEMO Code

First, create your image as you would normally. Then, create your various over states by doubling the canvas size of your image and putting the hover look in the new bottom half of the image. You will end up with something like this:

I hope your image looks better than this. http://demo.raleighbuckner./so/1369820/test.jpg

Next es the HTML and CSS. We will use an unordered list:

<style>
    #fakeMap { 
        list-style: none; margin: 0; padding: 0;  /* removes the default UL styling */
        position: relative;                       /* allows the LIs to be positioned */
        width: 200px;                             /* width of the image */
        height: 100px;                            /* height of the image */
        background: url(test.jpg) no-repeat 0 0; /* shows the image */      
    }
    #fakeMap li {
        position:absolute; /* these will be the "area" elements */
    }
    #fakeMap a {
        display:block;        /* along with the width and height, makes the link */
        width:100%;           /*  clickable for the full size of the LI          */
        height:100%;
        text-indent:-5000px;  /* pushes the text of the link offscreen */
    }

    /* Set up each LI to be the right size and positon. */
    #maplink1 { width:15px; height:15px; top:10px; left:10px; }
    #maplink2 { width:20px; height:20px; top:30px; left:30px; }
    #maplink3 { width:80px; height:30px; top:20px; left:70px; }

    /* Set the image for all of the links. */
    #fakeMap a:hover { background: url(test.jpg) no-repeat; }

    /* Set the position of the bg for each link individually. */
    #fakeMap #maplink1 a:hover { background-position:-10px -110px; }
    #fakeMap #maplink2 a:hover { background-position:-30px -130px; }
    #fakeMap #maplink3 a:hover { background-position:-70px -120px; }
</style>

<ul id="fakeMap">
    <li id="maplink1"><a href="link1.htm">Link 1 Text</a></li>
    <li id="maplink2"><a href="link2.htm">Link 2 Text</a></li>
    <li id="maplink3"><a href="link3.htm">Link 3 Text</a></li>
</ul> 

OK, my solution.

Start with an image map like so:

<img src="nav.jpg" id="main-nav" usemap="#imagemap" />              

<map id="imagemap" name="imagemap">
    <area id="item1" href="item1.shtml" shape="poly" coords="153,52,484,6,492,43,158,74" />
    <area id="item2" href="item2.shtml" shape="poly" coords="95,96,287,84,289,112,95,118,97,118" />
</map>

Then, I use jQuery to swap the SRC attribute of the IMG when the user hovers over each specific AREA, then return the IMG to the off state on mouseout.

$(document).ready(function() {

//set off state 
var nav_off = "/images/nav-off.jpg";

// functions for over and off
function over(image) {
    $("#main-nav").attr("src", image);
}
function off() {
    $("#main-nav").attr("src", nav_off);
}

$("#imagemap area").hover(
    function () {
        var button = $(this).attr("id");
        over("/images/nav-" + button + ".jpg");
    },
    function () {
        off();
    });

});

This could probably be bined with CSS Sprites somehow, swapping the background-position of some image during rollover.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745621369a4636537.html

相关推荐

  • Andorid平台实现高性能低延迟的多路RTSP播放器

    ​在当今的视频监控、流媒体传输等领域,RTSP(Real Time Streaming Protocol)协议被广泛用于音视频数据的实时传输。为了满足多路 RTSP 流的同时播放需求,基于大牛直播SDK开发了一款功能丰富、性能稳定的多路 R

    1小时前
    00
  • Ascend 910b 运行vllm报错 libatb.so: cannot open shared object file

    ascend上运行vllm报错, 说找不到 so库OSError: libatb.so: cannot open shared object file: No such file or directory代码语言:shell复制Loadin

    1小时前
    00
  • 动态渲染页面智能嗅探:机器学习判定AJAX加载触发条件

    爬虫代理本文提出了一种基于机器学习的智能嗅探机制,革新性地应用于自动判定动态渲染页面中AJAX加载的最佳触发时机。系统架构采用先进模块化拆解设计,由请求分析模块、机器学习判定模块、数据采集模块和文件存储模块四大核心部分构成。在核心代码示例中

    1小时前
    00
  • 告别复杂配置!中大型园区网络自动化开通流程实战解析

    到2025年,80%应用上云、30%流量为视频数据,传统网络无法支撑低时延、高可靠的云边协同需求。工业互联网场景中,TSN(时间敏感网络)等技术需网络架构深度重构以实现微秒级时延。传统园区网络的困境传统园区网络普遍存在部署周期长、管理复杂度

    1小时前
    00
  • 基于推理模型+RAG+Agent,作业帮内部安全体系建设实践

    文作业帮基础架构团队(吕亚霖、尚义龙) 背 景 在互联网智能化与 AI 大模型技术的双重驱动下,信息安全领域正遭遇史无前例的复杂挑战。从外部环境来看,AI 大模型的应用降低了攻击门槛。外部攻击者利用 AI 工具生成自动化攻击脚本、绕过

    56分钟前
    00
  • Adam获时间检验奖!清华揭示保辛动力学本质,提出全新RAD优化器

    新智元报道编辑:LRST【新智元导读】Adam优化器是深度学习中常用的优化算法,但其性能背后的理论解释一直不完善。近日,来自清华大学的团队提出了RAD优化器,扩展了Adam的理论基础,提升了训练稳定性。实验显示RAD在多种强化学习任务

    51分钟前
    10
  • 浅谈国产数据库多租户方案:提升云计算与SaaS的资源管理效率

    近年来,“数据库多租户”这一概念在技术圈内频频出现,成为云计算和SaaS(软件即服务)架构中的重要组成部分。多租户架构不仅为企业提供了高效的资源隔离与共享解决方案,还能大幅降低成本,提高系统的可扩展性与维护效率。很多人认为,它是SaaS模式

    50分钟前
    00
  • 从0到精通,System.Text.Json进阶技巧曝光,性能提升3倍!

    一、引言在现代软件开发中,JSON(JavaScript Object Notation)作为一种轻量级的数据交换格式,被广泛应用于前后端交互、配置文件管理以及分布式系统间的数据传输。System.Text.Json 是 .NET Core

    43分钟前
    00
  • 华为将大规模推出AI芯片,助力替代英伟达H100,打破限制!

    据路透社昨日凌晨独家报道,华为预计最早将在5月份推出大量910C AI芯片,部分产品已经开始出货。此次华为发布的新产品主要是为了应对美国对国内AI芯片的限制,助力国内企业缓解AI芯片供应紧张的问题。值得注意的是,本月美国政府要求英伟达销售H

    36分钟前
    00
  • UML 2.0中的14种图简介

    UML(统一建模语言)2.0中定义了14种不同类型的图表,用于从不同角度描述系统。这些图表分为结构图和行为图两大类。可使用 PlantUML 绘制 UML 中的各种类型的图表: PlantUML是一个通用性很强的工具,可以快速、直接地创建

    28分钟前
    00
  • Java 实现 MCP Server 以及常用 MCP 服务分享

    MCP 前段时间在 AI 领域 引发了 广泛关注,特别是在 各大海内外技术社区 中,大家热烈讨论,热度非常高,本文将带领大家使用 java 语言实现一个 mcp,揭开 mcp 这神秘的面纱,本文最后也推荐给大家一些常用的 MCP 服务,开箱

    26分钟前
    00
  • 如何搭建一个高效安全的API开放平台:完整步骤指南

    在当今数字化时代,API(应用程序编程接口)已成为连接不同系统和服务的桥梁。一个设计良好的API开放平台能够为企业带来巨大的商业价值和技术优势。本文将详细介绍从零开始搭建一个API开放平台的完整步骤,涵盖技术选型、架构设计、安全防护和运维管

    22分钟前
    00
  • Windows实用设置工具,你想要的系统功能它都有!

    各位系统调校爱好者们注意啦&#xff01;今天给大家安利一款装机必备的Windows实用工具包&#xff0c;堪称系统设置的"后悔药"&#xff0c;操作系统的"美图秀"&am

    13分钟前
    00
  • Mysql之存储过程

    1.存储过程概述 定义:MySQL 存储过程是一组预编译的 SQL 语句,它们被存储在数据库中,并可以通过调用来执行。用途:存储过程可以用于封装复杂的 SQL 操作、提高代码的重用性、增强数据操作的安全性和性能。特点:可以接受参数,也可以返

    11分钟前
    00
  • 从零到高手:轻松掌握蓝耘元生代 AIDC OS 中的 ComfyUI 抠图技术

    正文开始——一、引言 随着图像处理技术的不断发展,抠图作为其中的重要任务,广泛应用于电商、广告、创意设计等领域。蓝耘元生代 AIDC OS 中的 ComfyUI 工作流通过结合深度学习与先进的图像处理技术,提供了高效、精准的抠图解决方案。本

    9分钟前
    00
  • 初识Redis · 事务

    前言:前文我们花了大部分篇幅介绍了持久化,涉及到了RDB和AOF机制,涉及的文件有dump.rdb,appendonly.aof,涉及到的命令有save,bgsave,以及介绍了混合持久化的机制。并且理解了持久化主要是针对的Redis是一个

    7分钟前
    00
  • 【系统】换硬盘不换系统,使用WIN PE Ghost镜像给电脑无损扩容换硬盘

    文章目录 前言思路一、工具准备二、使用步骤1. 制作WIN PE 启动U盘2. 关机后接上过渡硬盘3. WIN PE 启动4. Ghost 克隆硬盘数据4. 关机替换nvme硬盘5. DiskGenius分区6. Ghost 还原分区7.

    6分钟前
    00
  • 初识Redis · 持久化

    前言:本文开始,就已经算是Redis的进阶篇文章啦,因为从本文开始就要开始涉及到了Redis的一些特性和一些底层原理了。那么首当其冲的,就是Redis中的持久化了,我们提及持久化之前,我们不妨回想一下MySQL中的事务有哪些特性,一共有4个

    6分钟前
    00
  • SQL 多表查询:数据整合与分析的强大工具

    SQL 多表查询:数据整合与分析的强大工具在关系型数据库中,数据通常被组织在多个表中。这种表的分离有助于减少冗余并提高数据的管理效率。然而,在实际应用中,往往需要对多个表中的数据进行整合查询,来获得更完整的信息。这时候,多表查询(Join)

    1分钟前
    00
  • 一键Wipe工具:数据清理与隐私保护指南

    本文还有配套的精品资源&#xff0c;点击获取简介&#xff1a;一键Wipe工具是IT领域中用于彻底清除设备数据、保护隐私和信息安全的重要工具。本文介绍了一键Wipe的功能、工作原理、应用场景、用户界面设计、使用风

    34秒前
    00

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信