chnage marquee direction on mouse over [duplicate]

女生的网名这么多〃 提交于 2021-02-11 15:22:43

问题


this is the code I have:

<a href="#" onMouseOver="document.getElementById('image_runner').direction='left';">LEFT</a>
     - <a href="#" onMouseOver="document.getElementById('image_runner').direction='right';">RIGHT</a>
<marquee direction="left" style="width: 900px; margin: auto;" id="image_runner" onMouseOver="document.getElementById('image_runner').stop();" onMouseOut="document.getElementById('image_runner').start();">
<ul style="margin-top:0px;">
  <li>asda</li>
  <li class="right">asdsa</li>
  <li class="right">assda</li>
</ul>
</marquee>

for some reason, it's not changing the direction of the marquee.

any ideas?


回答1:


Marquee cannot change direction while running. You have to stop it, change direction then start again, but it will start from the beggining.

document.getElementById('left').addEventListener('mouseover', function() {
  var marquee = document.getElementById('image_runner');
  marquee.stop();
  marquee.direction = 'left';
  marquee.start();
});
document.getElementById('right').addEventListener('mouseover', function() {
  var marquee = document.getElementById('image_runner');
  marquee.stop();
  marquee.direction = 'right';
  marquee.start();
});
<marquee direction="left" style="width: 900px; margin: auto;" id="image_runner" onMouseOver="document.getElementById('image_runner').stop();" onMouseOut="document.getElementById('image_runner').start();">
  <ul style="margin-top:0px;">
    <li>asda</li>
    <li class="right">asdsa</li>
    <li class="right">assda</li>
  </ul>
</marquee>
<a href="#" id="left">LEFT</a>
- <a href="#" id="right">RIGHT</a>


来源:https://stackoverflow.com/questions/34267073/chnage-marquee-direction-on-mouse-over

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!