Solved

javascript scrolling on click event

Posted on 2007-11-25
5
3,032 Views
Last Modified: 2010-04-21
This is the code:

<img src="images/scrolldown.gif"  onClick="frames['iframe'].scrollBy(0,50)"  >

'iframe' is some name of iframe that i want to scroll when image is clicked.

What i need is to scroll iframe when mouse button is pressed and while is pressed it should scroll for 50 px, until mouse is released. When it's released it should stop scroll.

I tried some loop but it doesn't work.
0
Comment
Question by:zvucini
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:Sinoj Sebastian
ID: 20346727
This may Help you. You can get the concept from this small page. You have to use "onmousedown" event from img tag and "onmouseup" from body tag.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<style type="text/css">
html,body{height:100%;}
body{background:#dee;}
div#divOne{margin:50px;height:300px;width:400px;background:#000;}
</style>
<script type="text/javascript">
function hi(){
document.getElementById('divTwo').innerHTML+="hi ";
}
</script>
</head>
<body onmouseup="if(window.sI)clearInterval(sI);">
<div id="divOne" onmousedown="sI=setInterval('hi()',10);">
</div>
<div id="divTwo">
</div>
</body>
</html>
0
 
LVL 2

Author Comment

by:zvucini
ID: 20346779
No, what i need is continuous scrolling od iframe until mouse is released. Now, it's scrolling only once.
0
 
LVL 12

Accepted Solution

by:
Sinoj Sebastian earned 500 total points
ID: 20346973
Iframe scrolling example


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<style type="text/css">
html,body{height:100%;}
body{background:#dee;}
</style>
<script type="text/javascript">

function scroll_iframe() {
  if (window.frames["iframe"]) {
    window.frames["iframe"].scrollBy(0, 5);
  }
}

</script>
</head>
<body onmouseup="if(window.sI)clearInterval(sI);">
<img src="http://www.roomforboxing.com/images/down-arrow.gif"  onmousedown="sI=setInterval('scroll_iframe()',10);"/>

<iframe name="iframe" id="iframe" src="page_two.html" width="100%" height="200" frameborder="0">Sorry, your browser doesn't support iframes.</iframe>
</body>
</html>
0
 
LVL 2

Author Closing Comment

by:zvucini
ID: 31410880
Great!
 
Best regards,
Zoran
0
 
LVL 2

Author Comment

by:zvucini
ID: 20347042
Perfect!

Best regards
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now