在给定坐标之间以相反的垂直方向滚动div

时间:2015-11-11 14:16:02

标签: javascript jquery

我有这段代码:

myDiv

当我向下滚动时,使用上面的代码0px-105px向上滚动到myDiv。我想要做的唯一更改是当我向下滚动时-105px0px向下滚动到static void Main(string[] args) { ServiceHost sh = new ServiceHost(typeof(ProblemSolver)); sh.AddServiceEndpoint( typeof(IProblemSolver), new NetTcpBinding(), "net.tcp://tjservicebus.servicebus.windows.net/solver"); Console.WriteLine("Add Binding End Point"); var key = "MYKEY"; sh.AddServiceEndpoint( typeof(IProblemSolver), new NetTcpRelayBinding(), ServiceBusEnvironment.CreateServiceUri("sb", "tjservicebus", "solver")) .Behaviors.Add(new TransportClientEndpointBehavior { TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("RootManageSharedAccessKey", key) }); sh.Open(); Console.WriteLine("Press ENTER to close"); Console.ReadLine(); sh.Close(); }

请帮忙吗?

2 个答案:

答案 0 :(得分:0)



$(window).scroll(function() {
  console.log(Math.max(-105, 0 - $(this).scrollTop()));
  $(".myDiv").animate({
    top: $(this).scrollTop()
  });
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style='height:200px;border:1px solid;position:relative;background:#ff6600' class='myDiv'>mydiv</div>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</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p;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
<P>&nbsp;</p>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

你必须绑定&#39; mousewheel&#39; event并检查originalEvent.wheelDelta。

代码:

$(window).bind('mousewheel DOMMouseScroll', function(event){
    if (event.originalEvent.wheelDelta > 0 || event.originalEvent.detail < 0)
        //up
    else
        //down
});