English 中文(简体)
jQuery鼠标移动停止
原标题:jQuery mousemove stop

费利克斯的英文翻译:

I want to create a menu which follows the mouse cursor and stops moving if the cursor is in a certain distance to it. My solution so far: I created two nested divs. In inner div contains the menu. The outer div is for stopping the menu. If the cursor moves over the outer div, the inner div should stop and stay as long as cursor hovers over it. *EDIT: And the menu should stop softly but quickly.

德语原件:

ich möchte ein Menü erstellen welches meinen Mauszeiger verfolgt und in bestimmter nähe stehen bleibt. Mein Lösungsansatz ist folgender: Ich baue 2 ineinander verschachtelte DIVs. Im inneren DIV ist das Menü vorhanden. Das äußere Div ist zum stoppen da. Also wenn ich mit dem Mauszeiger in das äußere Div gehe soll das innere DIV stark abbremsen und stehen bleiben, solange ich drin bin.

Hier mein derzeitiger代码(fw s:jQuery):

var div = jQuery("<div id= menubox ><div id= innerdiv >&nbsp;</div></div>").appendTo("body");

    var mouseX = 300, mouseY = 300;
    jQuery(document).mousemove(function (el) {
        if (onMenu == false) {
            mouseX = el.pageX;
            mouseY = el.pageY;
        }
    });

    jQuery( #menubox ).mouseenter(function (el) {
        onMenu = true;
        stopMoving();
    }).mouseleave(function (el) {
        onMenu = false;
        startMoving();
    });

    var xp = 0, yp = 0;
    function stopMoving() {
        clearTimeout(timer);
        timer = setTimeout(function () {
            clearInterval(loop);
        }, 100);
    }
    function startMoving() {
        clearTimeout(timer);
        clearInterval(loop);
        loop = setInterval(function () {
            xp += (mouseX - xp) / 20;
            yp += (mouseY - yp) / 20;
            jQuery( #menubox ).css({ left: xp, top: yp });
        }, 40);
    }
    startMoving(); // StartMoving on Page Load

*编辑:我有一个IE Bug。我不得不在外部div放置一个透明的gif。现在这个函数可以了。如果im在外部或内部div中,div不会移动,但不会很快停止。它应该非常柔软和快速地停止,不要移动,即200px,然后用clearInterval()停止或硬停止。我应该再做一个计时器吗?

问题回答

暂无回答




相关问题
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: &...

热门标签