R
R
russeljo2017-03-22 18:03:06
JavaScript
russeljo, 2017-03-22 18:03:06

How to fix the script so that it works in Firefox?

FF swears:

TypeError: e is undefined

I can't figure out what's wrong, everything works in chrome.
function move(e,b,r)    //для получения координат мышки
    {
        e = e || window.event
        if ( e.pageX == null 
             && e.clientX != null 
         ) 
            {
                var html = document.documentElement
                var body = document.body
                e.pageX = e.clientX + (html && html.scrollLeft || body && body.scrollLeft || 0) - (html.clientLeft || 0)
                e.pageY = e.clientY + (html && html.scrollTop || body && body.scrollTop || 0) - (html.clientTop || 0)
            }
        //устанавливаем тултип на уровне мышки
        jQuery('.tool').css('left',e.pageX + 15 + r + 'px');
        jQuery('.tool').css('top',e.pageY + 15 - b + 'px');
    }

It's taken from here Link
It doesn't work in FF either.
Tell me how to get this e ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
russeljo, 2017-03-23
@russeljo

Everything turned out to be simple, it was necessary to pass the event through jQuery.
As a result, this is what I got:

jQuery(document).ready(function(){
    
    jQuery('map area').mouseover(function(e){
        data = maparray[jQuery(this).index()];        
        jQuery('<div class="tool"></div>').appendTo('body').html(data);
        //console.log(e.clientX, e.clientY, e.pageX, e.pageY);        
        jQuery('.tool').css('left',e.pageX + 15  + 'px');
        jQuery('.tool').css('top',e.pageY + 15  + 'px');
    });

});

M
MrTimon, 2017-03-22
@MrTimon

You should pass event as the first parameter to the move function (and you, it seems to me, pass 0 there). In chrome, it works because e is replaced by window.event, while in FF there is no such value (The example you provided in the link also throws a TypeError: e is undefined on hover).
Looked at the example code. I suggest that the over function also add the e parameter and then transfer it to the move function. something like this:

function over(e,tip)	//функция при наведении
  {  
    //обрабатываем массив с данными
    data_color = '';
    data = maparray[tip-1];
    data = data.split(';');
    name = 	data[0]
    square = data[1]
    desc = data[2]
    //добавляем тултип
    $('').appendTo('body').html(name+' '+square+'кв.м.'+desc);
    move(e,0,0);
  }

then remove all inline calls to the over function and add the following code to the redi document:
$(document).ready(function(){
    $('area').mouseover(function(e) {
                      over(e,$(this).index()+1);
                });
  });

not tested but should work fine.

A
Alexey Sklyarov, 2017-03-22
@0example

jshint.com paste your code here and look for errors in the code, you simply miss ";"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question