首頁  >  問答  >  主體

javascript - jq怎麼做局部div滾動?

<style>
.top , .bottom{height:130px;background:#000;} .center{height:400px;overflow:hidden;position:relative;}
.center .box{ width:100%;height:100%;position:absolute;}
.center .box ul{overflow:hidden;}
.center .box ul li{background:red;height:400px;width:100 %;}
</style>

<p class="top"></p>

<p class="center">
    <p class="box">
        <ul>
        <li></li>
        <li></li>
        </ul>
    </p>
</p>

<p class="bottom"></p>

jq怎麼做ul li的局部滾動,中間這塊不能出現滾動條。也要考慮阻止瀏覽器滾動條事件。
需求是:用滑鼠滑輪滾動。 li會下滾或上滾。前提是我這個滑鼠在這裡center範圍,在範圍外面可以使用瀏覽器的滾動事件,裡面的禁止。

phpcn_u1582phpcn_u15822704 天前714

全部回覆(3)我來回復

  • 黄舟

    黄舟2017-05-24 11:38:08

    用這個scroll事件來控制box的position .

    回覆
    0
  • 滿天的星座

    滿天的星座2017-05-24 11:38:08

    透過scroll事件來取得滾動的方向,透過你自己的程式計算來調整p的position,css3可以用transform,不支援css3用left,top

    回覆
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-24 11:38:08

    外層包裹一個p,設定overflow:hidden,剛好覆蓋住內層的捲軸。
    滑鼠滾動事件。 $('.center').on()回應滑鼠事件,然後阻止冒泡即可。

    回覆
    0
  • 取消回覆