English 中文(简体)
页: 1 三个要素作为一要素处理
原标题:jQuery treat hover on two elements as one element
  • 时间:2011-11-22 16:59:52
  •  标签:
  • jquery

I have an image map which I have overlaid with some markers in the form of anchors. I currently have a hover trigger on each image map area and the associated anchor - as shown in screen shot enter image description here

我需要将这两个要素作为一处理,因为目前,这些改动从一个单元移至另一个单元,它称作hover(<>,并再次发出呼吁。 我只想把 h击指从两个要素中去掉。

问题回答
$( #areaID1, #areaID2 ).hover(function(){
    //same mouseover event
}, function(){
    //same mouseout event
});

我使用的是:

MAP.area = $( #centre_map area, #map ol li );
MAP.area.hover(function() {
    // Add active classes
    // Load content
    load_map_activity($( body ).attr( id ), $(this).attr( class ));
}, function() {
    // Remove active classes
})


<div id="map">
<img src="<?php echo base_url(); ?>images/bristol_map.png" alt="bristol map" usemap="#centre_map" />
<map name="centre_map" id="centre_map">
    <area shape="poly" coords="179,95,188,87,187,53,181,48,54,29,41,38,37,53,39,77,44,87" href="#" class="paintball" alt="Paintballing" />
</map>
<ol>
    <li class="paintball"><a class="marker paintball" href="#" title="Paintballing">1</a></li>
</ol>

Rory McCrossan 我将试图这样做,但我担心,因为主线被放在图像地图区一带,当 mo被移至 anchor(尽管我们仍位于地图区)时,会再次发出 h。

我已设法取得预期结果——我从错误的角度来审视这个问题,这不是一个 h问题,而是使麻风病更加严重。

    MAP.area = $( #centre_map area, #map ol li );
MAP.area.hover(function() {
    // Add active classes
    $( #map_key ol li a. +$(this).attr( class )).addClass( active );
    $( #map ol li a. +$(this).attr( class )).addClass( active );

    if(typeof MAP.current_content ==  undefined )
    {
        // Load content
        load_map_activity($( body ).attr( id ), $(this).attr( class ));
    }

    if(MAP.current_content != $(this).attr( class ))
    {
        $( #map_info > * ).remove();
        // Load content
        load_map_activity($( body ).attr( id ), $(this).attr( class ));
    }
}, function() {
    // Remove active classes
    $( #map_key ol li a. +$(this).attr( class )).removeClass( active );
    $( #map ol li a. +$(this).attr( class )).removeClass( active );
})


function load_map_activity(centre, activity) {
    MAP.current_content = activity;
    $( #map_info ).hide().load( /ajax/ +centre+ _ +activity, {}, function() { $(this).fadeIn( fast ); });
}

感谢所有帮助者。

你们说,你需要把这两个要素当作一个因素来处理,以便你能够制造一个母集装箱,而在这个集装箱里,你可以很容易地约束事件。

<div id="mapContainer">
   <div id="areaID1"> xyz </div>
   <div id="areaID2"> xyz </div>
</div>

$( #mapContainer ).hover(function(){
    //do anything
    }, function(){
    //do anything
});




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签