Solved

javascript scrolling on click event

Posted on 2007-11-25
5
3,058 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

808 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