Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

textarea like thingy 2

Status
Not open for further replies.

gagz

Programmer
Nov 21, 2002
333
US
Is there anyway I can do something that has the same affect as a textarea (ie, fixed width, scrolling), but is not edittable and accepts html tags?

thanks.
 
Yep... use DIV container w/ fixed width/height and set overflow (CSS2):

Code:
<div style="width:200px; height: 100px; border: solid #000000 1px; overflow: auto;">
... insert HTML here...
</div>
 
wow! i have never seen that attribute. You are my new hero.
 
just as an aside. I had a user request that for just this div tag, shut off scrolling with his middle mouse button, because when there are a bunch of these on teh page, it make scrolling the actual page a pain. I'm under the impression that I cannot do it for just this tag, and not his whole client browser.... any ideas?
 
If DIV's are running slowly, any alternative will run even slower. In fact, I don't think scrolling off will improve performance at all.

Anyway, scrolling can't be easily disabled. You can switch overflow on click between auto and hidden. This isn't perfect because clipping resets to (0, 0) and scrollbars disappear, so you'll probably need to refine code:

Code:
<div blah blah... overflow: auto;" onclick="changeDIVScrolling(this);">
...
<script language="javascript">
function changeDIVScrolling( oDiv )
{	with (oDiv.style)
		overflow= (overflow=="auto"? "hidden": "auto");
}
</script>

To switch all necessary DIVs, assign them unique ID and prefix, then use another function that calls previous one:
Code:
<div id="scroll1"... onclick="changeAllScrollings(this);"> ... </div>
<div id="scroll2"... onclick="changeAllScrollings(this);"> ... </div>
...
function changeAllScrollings()
{	oDivs = document.getElementsByTagName( "DIV" );
	for( var i=0; i<oDivs.length; i++ )
		if (oDivs[i].id.substring(0, 6)=="scroll")
			changeDIVScrolling( oDivs[i] );
}
 

This will allow you to disable scrolling using the mouse wheel:

Code:
<html>
<head></head>
<body>
	<div style="width:100px;height:100px;overflow:auto;border:1px #000000 solid;" onmousewheel="return(false);">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas imperdiet ultrices lacus. Mauris faucibus lacus.</div>
</body>
</html>

Basically, adding the onmousewheel="return(false);" code to the DIV.

Hope this helps,
Dan
 
Problem w/ onmousewheel is that it only works in IE6... but thanks anyway.
 
i'll give that a shot... 95% at least of our users are IE6, so as long as it doesn't break anything else...
 
i think I have a slightly different interpretation of the user's problem...


when there's a whole bunch of these on a long page, the user starts scrolling down - with the wheel - but the mouse ends up over this div, or the div has the focus...and so the div scrolls instead.

instead of 10 scrolls to the bottom of the page, the user now faces 50, or 100....

Simply put, you want the mouse wheel to ALWAYS scroll the page, no matter which element has the focus or is hovered over.

In which case, whenever the user scrolls the wheelyou want to pass the event to the page instead of any other element.

sorry I can't offer any code straight away, but the principal's there...

<marc> i wonder what will happen if i press this...[ul][li]please tell us if our suggestion has helped[/li][li]need some help? faq581-3339[/li][/ul]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top