1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Random GIF with play on mouse over function

Discussion in 'HTML & JavaScript' started by blueheaven, Nov 4, 2013.

  1. blueheaven

    blueheaven Newbie

    Joined:
    Jun 5, 2013
    Messages:
    11
    Likes Received:
    0
    Occupation:
    Freelancer
    Hey everybody! I am quite new to programming and I am having a problem. I am using a script shown below which loads random GIF every time you enter the site. But I want that my GIF would only start to animate on mouse hover. Is that possible with the random GIF script I am using? Thanks in advance.

    SCRIPT: pastebin.com/N39fDMRH
     
    Last edited: Nov 4, 2013
  2. tripper_john_md

    tripper_john_md Newbie

    Joined:
    Feb 21, 2011
    Messages:
    40
    Likes Received:
    35
    Location:
    Southern Germany
    Yes, it is possible. But there is no way to control a gif, so you'll need two files for every gif, one animated and one that only displays whatever you want to have displayed (e.g. first frame of the gif).
    Then add an event handler for mouseover that changes the img src to the animated version and, if you want to stop it again, an event handler for mouseout that changes the img src back to the static version.