简体   繁体   中英

as3 mouse wheel reverse

Hey i built custom scroll box. When i scroll up on this box scrolling element is going down and when i scroll down - scrolling element is going up ;). I whant to reverse that mechanism. how can i do it ? Below my code for mouse

import flash.events.MouseEvent;

function handleMouseWheel(event:MouseEvent):void {
    if ((event.delta > 0 && box_mc.y < 171) || (event.delta < 0 && box_mc.y > 135)) 
    {

        box_mc.y = box_mc.y + (event.delta * 3);
        sb.thumb.y = sb.thumb.y + (event.delta * 13);

        trace(box_mc.y);
        trace(event.delta);

    }
}
stage.addEventListener(MouseEvent.MOUSE_WHEEL, handleMouseWheel);

All you need to do is invert the delta value (or the direction in which you scroll):

if ((event.delta > 0 && box_mc.y < 171) || (event.delta < 0 && box_mc.y > 135)) 
{

    box_mc.y = box_mc.y + (-event.delta * 3);
    sb.thumb.y = sb.thumb.y + (-event.delta * 13);

    trace(box_mc.y);
    trace(event.delta);

}

Notice all I have done is put a minus symbol in front of the event.delta value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM