javascript - Un-ending image using mouse scroll -


<!doctype html> <html> <head>     <meta http-equiv="content-type" content="text/html; charset=utf-8" />     <title>frog</title>     <script type="text/javascript">         window.onscroll = infinity;         function infinity () {             document.write("<img src='frog.gif'>" + "<br/>");         }         while(window.onscroll){             infinity();         }     </script> </head> <body>     <img src='earth.png'>      <br/>     <img src='tiger.jpg'>      <br/> </body> </html> 

hi guys, want know how loop frog when every time scroll down frog image appears again in advance!

if need add image when user turns mouse wheel (even when no actual scrolling involved) - need capture "mousewheel" event. universally crossbrowser can this:

if (document.addeventlistener) {     document.addeventlistener("mousewheel", mousewheelhandler, false);     document.addeventlistener("dommousescroll", mousewheelhandler, false); } else {     document.attachevent("onmousewheel", mousewheelhandler); }     

if create placeholder hold future images:

<div id="fdiv">froggies:</div> 

you can add images on mousewheeling this:

function mousewheelhandler(e) {      var e = window.event || e;     var delta = e.wheeldelta      if (delta < 0)      var img = document.createelement("img");     img.src = "frog.gif";     document.getelementbyid("fdiv").appendchild(img);  } 

what detects whether user scrolls mouse down (delta < 0) , if - creates new frog image , adds div.

here's demo: http://jsfiddle.net/z8axg/2/ place mouse on window words "froggies:" , turn mouse wheel down.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -