I have a function where I am trying to create a scrolling effect on the div’s content by using an event for mouse wheel.
The listener:
document.getElementById('menu_base').addEventListener("mousewheel", scrollfunc, false);
I have this for my scroll event:
function scrollfunc(e){
console.log(e);
if(e.wheelDeltaY == 120) { //this does work
document.getElementById('menu_base').style.marginTop += 50; //no change
} else if(e.wheelDeltaY == -120){ //as does this
document.getElementById('menu_base').style.marginTop -= 50; //no change
}
}
The console.log shows:
WheelEvent {webkitDirectionInvertedFromDevice: false, wheelDeltaY: -120, wheelDeltaX: 0, wheelDelta: -120, webkitMovementY: 0…}
menu_base properties are:
.menu_base{
width:100%;
height:600px;
position:absolute;
left: 0;
top: 0;
text-align:center;
border:1px solid black;
overflow:hidden;
}
Yet the content does not move, marginTop does not seem to alter.
Any suggestions on what might be the probable cause ?
You need to define the
marginTopwith an unit, e.g. usingpx:Fiddle