javascript - How can I control an image's size -



javascript - How can I control an image's size -

i skilled database / application programmer pc. ignorant html / javascript / web programmer.

i creating documentation .net assemblies our intranet. ideally display image total size if browser window can fit it. if not cut down , toggle between little version , total size version click. dependency chart , can different sizes different pages. prefer single function handle beingness our utilize none of requirements mentioned set in stone. create work nil mandatory.

i read lot of stuff couldn't find matched wanted. first tried (after few iterations):

<img src='dependancy charts/rotairaorfq.png' width='100%' onclick='this.src="dependancy charts/rotairaorfq.png";this.width=this.naturalwidth;this.height=this.naturalheight;' ondblclick='this.src="dependancy charts/rotairaorfq.png";this.width="100%";'>

it has problems. first off enlarges little image , looks funny. sec have set code in every page. 3rd requires double click restore it. going live short commings double click fails. can't figure out how restore it.

so tried fancy. couldn't figure out how past problem 1, solved 2 , 3 creating function in separate file. ran appeared same problem. sec attempt:

function imagetoggle(image) { if (imagetoggle.fullsize == 'undefined') imagetoggle.fullsize = false; if (imagetoggle.fullsize) { image.width='100%'; imagetoggle.fullsize = false; } else { image.width=image.naturalwidth; imagetoggle.fullsize = true; } homecoming 0 }

and in page:

<img src='dependancy charts/rotairaorfq.png' width='100%' onclick='imagetoggle(this)'>

can want done? doesn't sound impossible. if big amount of effort required alternate suggestions acceptable.

you're interested in max-width: 100% css property, rather flat-out width:100%. if have tiny image, it'll remain tiny. if have huge image, gets resized width of containing element.

for example: http://jsbin.com/kabepo/1/edit uses little , huge image, both max-width:100%. can see, little image untouched, huge image resized sensible.

javascript html css

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -