Solved

javascript scrolling on click event

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Angular - why isn't this ng-if isn't working? 4 36
My dialog box isnt work, no box displays but text does 8 38
jQuery Syntax 2 47
Change javascript css 1 19
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

912 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

25 Experts available now in Live!

Get 1:1 Help Now